home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 May / SGI IRIX 6.5 Applications 1999 May.iso / dist / nss_fasttrack.idb / var / netscape / fasttrack / include / nsapi.h.z / nsapi.h
C/C++ Source or Header  |  1998-10-13  |  111KB  |  3,474 lines

  1. /*
  2.    PROPRIETARY SOURCE CODE OF NETSCAPE COMMUNICATIONS CORPORATION.
  3.  
  4.    Copyright (c) 1994, 1995, 1996, and 1997 Netscape Communications
  5.    Corporation.  All rights reserved.
  6.  
  7.    Use of this Source Code is subject to the terms of the applicable
  8.    license agreement from Netscape Communications Corporation.
  9. */
  10.  
  11. #ifndef PUBLIC_NSAPI_H
  12. #define PUBLIC_NSAPI_H
  13.  
  14. /*
  15.  * File:        nsapi.h
  16.  *
  17.  * Description:
  18.  *
  19.  *      This file defines an interface for extending the server with
  20.  *      in-process plug-ins.
  21.  */
  22.  
  23. #include "base/systems.h"
  24.  
  25. #if defined(FILE_UNIX_MMAP) || defined(FILE_WIN32_MMAP)
  26. #define FILE_MMAP
  27. #endif
  28.  
  29. /* --- Begin miscellaneous definitions --- */
  30.  
  31. /* Used in some places as a length limit on error messages */
  32. #define MAGNUS_ERROR_LEN 1024
  33.  
  34. /* Carriage return and line feed */
  35. #define CR 13
  36. #define LF 10
  37. #ifdef XP_WIN32
  38. #define ENDLINE "\r\n"
  39. #else
  40. #define ENDLINE "\n"
  41. #endif
  42.  
  43. /* mime.types file identification line */
  44. #define NCC_MT_MAGIC "#--Netscape Communications Corporation MIME Information"
  45. #define NCC_MT_MAGIC_LEN 55
  46.  
  47. /* Deprecated */
  48. #define MCC_MT_MAGIC "#--Mosaic Communications Corporation MIME Information"
  49. #define MCC_MT_MAGIC_LEN 53
  50.  
  51. /* The character which separates extensions with cinfo_find */
  52. #define CINFO_SEPARATOR '.'
  53.  
  54. /* The maximum length of a line in a mime.types file */
  55. #define CINFO_MAX_LEN 1024
  56.  
  57. /*
  58.  * The maximum length of an error message. NOT RUN-TIME CHECKED
  59.  */
  60.  
  61. #define MAX_ERROR_LEN 1024
  62.  
  63. /* A warning is a minor mishap, such as a 404 being issued. */
  64. #define LOG_WARN 0
  65.  
  66. /* 
  67.  * A misconfig is when there is a syntax error or permission violation in
  68.  * a config. file.
  69.  */
  70. #define LOG_MISCONFIG 1
  71.  
  72. /* 
  73.  * Security warnings are issued when authentication fails, or a host is
  74.  * given a 403 return code.
  75.  */
  76. #define LOG_SECURITY 2
  77.  
  78. /*
  79.  * A failure is when a request could not be fulfilled due to an internal
  80.  * problem, such as a CGI script exiting prematurely, or a filesystem 
  81.  * permissions problem.
  82.  */
  83. #define LOG_FAILURE 3
  84.  
  85. /*
  86.  * A catastrophe is a fatal server error such as running out of
  87.  * memory or processes, or a system call failing, or even a server crash. 
  88.  * The server child cannot recover from a catastrophe.
  89.  */
  90. #define LOG_CATASTROPHE 4
  91.  
  92. /*
  93.  * Informational message, of no concern.
  94.  */
  95. #define LOG_INFORM 5
  96.  
  97. /*
  98.  * Internal log messages to be logged.  Internal use only.
  99.  * Enable with "LogVerbose on" in magnus.conf
  100.  */
  101. #define LOG_VERBOSE 6
  102.  
  103. /*
  104.  * The time format to use in the error log
  105.  */
  106.  
  107. #define ERR_TIMEFMT "[%d/%b/%Y:%H:%M:%S]"
  108.  
  109.  
  110. /* The fd you will get if you are reporting errors to SYSLOG */
  111.  
  112. #define ERRORS_TO_SYSLOG -1
  113.  
  114. /* Return codes from file I/O routines */
  115. #define IO_OKAY 1
  116. #define IO_ERROR -1
  117. #define IO_EOF 0
  118. #define NETBUF_EOF    -1
  119. #define NETBUF_ERROR    -2
  120.  
  121. /* The disk page size on this machine. */
  122. #define FILE_BUFFERSIZE 4096
  123.  
  124. #ifdef XP_UNIX
  125.  
  126. #define FILE_PATHSEP '/'
  127. #define FILE_PARENT "../"
  128.  
  129. #elif defined(XP_WIN32)
  130.  
  131. #define FILE_PATHSEP '/'
  132. #define FILE_PARENT "..\\"
  133.  
  134. #endif /* XP_WIN32 */
  135.  
  136. #define NET_INFINITE_TIMEOUT 0
  137. #define NET_ZERO_TIMEOUT -1
  138.  
  139.  
  140. /*
  141.  * The following macros allow code to be written to use either the
  142.  * shell expression API defined here, or the regular expression
  143.  * pattern matching API defined in regexp.h.  Regular expressions
  144.  * have a more complicated syntax, but also are more powerful.
  145.  * Define the symbol, USE_REGEX to use regular expressions.  You
  146.  * can include either or both of shexp.h and regexp.h, regardless
  147.  * of whether USE_REGEX is defined or not, and the WILDPAT macros
  148.  * will be defined appropriately.
  149.  */
  150.  
  151. #ifdef USE_REGEX
  152.  
  153. #define WILDPAT_VALID(exp)              regexp_valid(exp)
  154. #define WILDPAT_MATCH(str, exp)         regexp_match(str, exp)
  155. #define WILDPAT_CMP(str, exp)           regexp_cmp(str, exp)
  156. #define WILDPAT_CASECMP(str, exp)       regexp_casecmp(str, exp)
  157. #define WILDPAT_USES_REGEXP             1
  158.  
  159. /* Define return codes from WILDPAT_VALID */
  160. #define NON_WILDPAT     -1              /* exp is ordinary string */
  161. #define INVALID_WILDPAT -2              /* exp is an invalid pattern */
  162. #define VALID_WILDPAT   1               /* exp is a valid pattern */
  163.  
  164. #else
  165.  
  166. /* WILDPAT uses shell expressions */
  167. #define WILDPAT_VALID(exp)              shexp_valid(exp)
  168. #define WILDPAT_MATCH(str, exp)         shexp_match(str, exp)
  169. #define WILDPAT_CMP(str, exp)           shexp_cmp(str, exp)
  170. #define WILDPAT_CASECMP(str, exp)       shexp_casecmp(str, exp)
  171. #define WILDPAT_USES_SHEXP              1
  172.  
  173. /* Define return codes from WILDPAT_VALID */
  174. #define NON_WILDPAT     -1              /* exp is ordinary string */
  175. #define INVALID_WILDPAT -2              /* exp is an invalid pattern */
  176. #define VALID_WILDPAT   1               /* exp is a valid pattern */
  177.  
  178. #endif /* USE_REGEX */
  179.  
  180. /* Define return codes from regexp_valid and shexp_valid */
  181. #define NON_SXP         NON_WILDPAT     /* exp is an ordinary string */
  182. #define INVALID_SXP     INVALID_WILDPAT /* exp is an invalid shell exp */
  183. #define VALID_SXP       VALID_WILDPAT   /* exp is a valid shell exp */
  184.  
  185. #ifdef USE_REGEX
  186. /* and regexp versions */
  187. #define NON_REGEXP      NON_SXP
  188. #define INVALID_REGEXP  INVALID_SXP
  189. #define VALID_REGEXP    VALID_SXP
  190. #endif
  191.  
  192. #define SYSTHREAD_DEFAULT_PRIORITY 16
  193.  
  194. /* The longest line in the configuration file */
  195. #define CONF_MAXLEN 16384
  196.  
  197. #define HTTP_DATE_LEN 128
  198. #ifdef XP_UNIX
  199. #define HTTP_DATE_FMT "%A, %d-%b-%y %T GMT"
  200. #else /* XP_WIN32 */
  201. #define HTTP_DATE_FMT "%A, %d-%b-%y %H:%M:%S GMT"
  202. #endif /* XP_WIN32 */
  203.  
  204. /* HTTP status codes */
  205. #define PROTOCOL_CONTINUE 100        /* HTTP/1.1 */
  206. #define PROTOCOL_SWITCHING 101        /* HTTP/1.1 */
  207. #define PROTOCOL_OK 200
  208. #define PROTOCOL_CREATED 201
  209. #define PROTOCOL_NO_RESPONSE 204
  210. #define PROTOCOL_PARTIAL_CONTENT 206
  211. #define PROTOCOL_REDIRECT 302
  212. #define PROTOCOL_NOT_MODIFIED 304
  213. #define PROTOCOL_BAD_REQUEST 400
  214. #define PROTOCOL_UNAUTHORIZED 401
  215. #define PROTOCOL_FORBIDDEN 403
  216. #define PROTOCOL_NOT_FOUND 404
  217. #define PROTOCOL_METHOD_NOT_ALLOWED 405    /*HTTP/1.1 */
  218. #define PROTOCOL_PROXY_UNAUTHORIZED 407
  219. #define PROTOCOL_CONFLICT 409            /* HTTP/1.1 */
  220. #define PROTOCOL_LENGTH_REQUIRED 411    /*HTTP/1.1 */
  221. #define PROTOCOL_PRECONDITION_FAIL 412     /*HTTP/1.1 */
  222. #define PROTOCOL_ENTITY_TOO_LARGE 413    /*HTTP/1.1 */
  223. #define PROTOCOL_URI_TOO_LARGE 414        /*HTTP/1.1 */
  224. #define PROTOCOL_SERVER_ERROR 500
  225. #define PROTOCOL_NOT_IMPLEMENTED 501
  226. #define PROTOCOL_VERSION_NOT_SUPPORTED 505 /*HTTP/1.1 */
  227.  
  228. #define CURRENT_PROTOCOL_VERSION 101
  229.  
  230. /* Definitions for HTTP over SSL */
  231. #define HTTPS_PORT 443
  232. #define HTTPS_URL "https"
  233.  
  234. /* Definitions for HTTP over TCP */
  235. #define HTTP_PORT 80
  236. #define HTTP_URL "http"
  237.  
  238.  
  239. #define REQ_MAX_LINE 4096
  240.     
  241. /*
  242.  * The REQ_ return codes. These codes are used to determine what the server
  243.  * should do after a particular module completes its task.
  244.  *
  245.  * Func type functions return these as do many internal functions.
  246.  */
  247.  
  248. /* The function performed its task, proceed with the request */
  249. #define REQ_PROCEED 0
  250. /* The entire request should be aborted: An error occurred */
  251. #define REQ_ABORTED -1
  252. /* The function performed no task, but proceed anyway. */
  253. #define REQ_NOACTION -2
  254. /* Tear down the session and exit */
  255. #define REQ_EXIT -3
  256. /* Restart the entire request-response process */
  257. #define REQ_RESTART -4
  258.  
  259. /* --- End miscellaneous definitions --- */
  260.  
  261. /* --- Begin native platform includes --- */
  262.  
  263. #if defined(FILE_UNIX) || defined(FILE_UNIX_MMAP)
  264. #include <sys/types.h>                  /* caddr_t */
  265. #include <sys/file.h>
  266. #include <fcntl.h>
  267. #include <unistd.h>
  268. #endif
  269.  
  270. #ifdef FILE_WIN32
  271. #include <direct.h>
  272. #endif /* FILE_WIN32 */
  273.  
  274. #ifdef NET_WINSOCK
  275. #include <winsock.h>
  276. struct iovec {
  277.     char        *iov_base;
  278.     unsigned    iov_len;
  279. };
  280. #else
  281. #if !defined(SUNOS4) && !defined(HPUX)
  282. #include <sys/select.h>
  283. #endif
  284. #include <sys/time.h>    /* struct timeval */
  285. #include <sys/socket.h>
  286. #include <netinet/in.h> /* sockaddr and in_addr */
  287. #include <sys/uio.h>
  288. #endif /* NET_WINSOCK */
  289.  
  290. #include <sys/stat.h>
  291.  
  292. #include <ctype.h>  /* isspace */
  293. #include <stdio.h>
  294. #include <stdarg.h>
  295. #include <stdlib.h>
  296. #include <string.h>
  297. #include <errno.h>
  298. #include <time.h>
  299.  
  300. #ifdef XP_UNIX
  301. #include <dirent.h>
  302. #include <pwd.h>                /* struct passwd */
  303. #endif /* XP_UNIX */
  304.  
  305. /* --- End native platform includes --- */
  306.  
  307. /* --- Begin type definitions --- */
  308.  
  309. #ifndef SYS_FILE_T
  310. typedef void *SYS_FILE;
  311. #define SYS_FILE_T void *
  312. #endif /* !SYS_FILE_T */
  313.  
  314. #define SYS_ERROR_FD ((SYS_FILE)-1)
  315.  
  316. #ifndef SYS_NETFD_T
  317. typedef void *SYS_NETFD;
  318. #define SYS_NETFD_T void *
  319. #endif /* !SYS_NETFD_T */
  320.  
  321. /* Error value for a SYS_NETFD */
  322. #ifndef SYS_NET_ERRORFD
  323. #define SYS_NET_ERRORFD ((SYS_NETFD)-1)
  324. #endif /* !SYS_NET_ERRORFD */
  325.  
  326. /*
  327.  * Type:        filebuffer, filebuf_t
  328.  *
  329.  * Description:
  330.  *
  331.  *      This structure is used to represent a buffered file.  On some
  332.  *      systems the file may be memory-mapped.  A filebuffer is created
  333.  *      by filebuf_open(), and destroyed by filebuf_close().
  334.  *
  335.  * Notes:
  336.  *
  337.  *      Direct access to the members of this structure, not using
  338.  *      macros defined here, is discouraged.
  339.  *
  340.  *      The filebuf alias that used to be defined for this type was
  341.  *      found to conflict with a C++ class of the same name, so it
  342.  *      has been renamed to filebuf_t.
  343.  *
  344.  *      The inbuf field used to be (char *), but is now (unsigned char *)
  345.  *      to simplify handling of 8-bit data.  The value returned by the
  346.  *      filebuf_getc() macro is the (unsigned char) casted to (int), or
  347.  *      an error code.  Unfortunately, IO_EOF cannot be distinguished
  348.  *      from a zero byte, but a new function, filebuf_iseof(), is
  349.  *      provided that will indicate definitively whether EOF has been
  350.  *      reached.
  351.  */
  352.  
  353. #ifdef FILE_MMAP
  354.  
  355. /* Version of filebuffer when memory-mapped files are supported */
  356. typedef struct {
  357.     SYS_FILE fd;
  358. #ifdef FILE_UNIX_MMAP
  359.     caddr_t fp;
  360. #else /* FILE_WIN32_MMAP */
  361.     HANDLE fdmap;
  362.     char *fp;
  363. #endif /* FILE_UNIX_MMAP */
  364.     int len;
  365.  
  366.     unsigned char *inbuf;   /* for buffer_grab */
  367.     int cursize;
  368.  
  369.     int pos;
  370.     char *errmsg;
  371. } filebuffer;
  372.  
  373. /* Return next character or IO_EOF */
  374. #define filebuf_getc(b) ((b)->pos == (b)->len ? IO_EOF : (int)(unsigned char *)((b)->fp)[(b)->pos++])
  375.  
  376. #define filebuf_iseof(b) ((b)->pos == (b)->len)
  377.  
  378. #else
  379.  
  380. /* Version of filebuffer with no memory-mapped file support */
  381. typedef struct {
  382.     SYS_FILE fd;
  383.  
  384.     int pos, cursize, maxsize;
  385.     unsigned char *inbuf;
  386.     char *errmsg;
  387. } filebuffer;
  388.  
  389. /* Return next character, IO_EOF, or IO_ERROR */
  390. #define filebuf_getc(b) \
  391.  ((b)->pos != (b)->cursize ? (int)((b)->inbuf[(b)->pos++]) : filebuf_next(b,1))
  392.  
  393. #endif /* FILE_MMAP */
  394.  
  395. /* C++ streamio defines a filebuf class. */
  396. typedef filebuffer filebuf_t;
  397.  
  398. #ifdef XP_WIN32
  399. /* Use a filebuffer to read data from a pipe */
  400. #define pipebuf_getc(b) \
  401.  ((b)->pos != (b)->cursize ? (int)((b)->inbuf[(b)->pos++]) : pipebuf_next(b,1))
  402. #endif /* XP_WIN32 */
  403.  
  404. /*
  405.  * Type:        netbuf
  406.  *
  407.  * Description:
  408.  *
  409.  *      This structure is used to represent a buffered network socket.
  410.  *      It is created by netbuf_open(), and destroyed by netbuf_close().
  411.  *
  412.  * Notes:
  413.  *
  414.  *      Direct access to the members of this structure, not using
  415.  *      macros defined here, is discouraged.
  416.  *
  417.  *      The inbuf field used to be (unsigned char *), but is now
  418.  *      simply (char *).  The value returned by the netbuf_getc()
  419.  *      macro is (int).
  420.  */
  421.  
  422. typedef struct {
  423.     SYS_NETFD sd;
  424.  
  425.     int pos, cursize, maxsize, rdtimeout;
  426. #ifdef XP_WIN32
  427.     CHAR address[64];
  428. #endif /* XP_WIN32 */
  429.     unsigned char *inbuf;
  430.     char *errmsg;
  431. #ifndef XP_WIN32
  432.     char address[64];
  433. #endif /* !XP_WIN32 */
  434. } netbuf;
  435.  
  436. /*
  437.  * netbuf_getc gets a character from the given network buffer and returns 
  438.  * it. (as an integer).
  439.  * 
  440.  * It will return (int) IO_ERROR for an error and (int) IO_EOF for
  441.  * an error condition or EOF respectively.
  442.  */
  443.  
  444. #define netbuf_getc(b) \
  445.  ((b)->pos != (b)->cursize ? (int)((b)->inbuf[(b)->pos++]) : netbuf_next(b,1))
  446.  
  447. /*
  448.  * buffer_error returns the last error that occurred with buffer. Don't use
  449.  * this unless you know an error occurred. Independent of network/file type.
  450.  */
  451.  
  452. #define buffer_error(b) ((b)->errmsg)
  453.  
  454. /*
  455.  * Type:        cinfo
  456.  *
  457.  * Description:
  458.  *
  459.  *      This is a structure that captures the information in the name/value
  460.  *      pairs on one line of a mime.types file.  A cinfo structure is
  461.  *      stored in the memory-resident database, indexed by each of the
  462.  *      file extensions specified in the "exts" name/value pair.  It
  463.  *      defines various attributes of resources with names containing
  464.  *      the specified file extensions.
  465.  *
  466.  * Notes:
  467.  *
  468.  *      Pointers to cinfo structures returned by this API may or may not
  469.  *      need to freed by the caller.  See the individual function
  470.  *      descriptions.
  471.  *
  472.  *      The strings referenced by the fields of cinfo structures returned
  473.  *      by this API should be considered read-only, and do not need to be
  474.  *      freed by the caller, even when the cinfo structure does.
  475.  */
  476.  
  477. typedef struct {
  478.     char *type;
  479.     char *encoding;
  480.     char *language;
  481. } cinfo;
  482.  
  483.  
  484. typedef void* CONDVAR;
  485. typedef void *COUNTING_SEMAPHORE;
  486. typedef void* CRITICAL;
  487.  
  488. #ifdef XP_UNIX
  489. typedef struct passwd *PASSWD;
  490. typedef DIR* SYS_DIR;
  491. typedef struct dirent SYS_DIRENT;
  492. #endif /* XP_UNIX */
  493.  
  494. #ifdef XP_WIN32
  495.  
  496. typedef struct {
  497.     char *d_name;
  498. } dirent_s;
  499.  
  500. typedef struct {
  501.     HANDLE dp;
  502.     WIN32_FIND_DATA fdata;
  503.     dirent_s de;
  504. } dir_s;
  505.  
  506. typedef dir_s* SYS_DIR;
  507. typedef dirent_s SYS_DIRENT;
  508.  
  509. #endif /* XP_WIN32 */
  510.  
  511. typedef struct {
  512.     char *name,*value;
  513. } pb_param;
  514.  
  515. struct pb_entry {
  516.     pb_param *param;
  517.     struct pb_entry *next;
  518. };
  519.  
  520. typedef struct {
  521.     int hsize;
  522.     struct pb_entry **ht;
  523. } pblock;
  524.  
  525. #ifndef POOL_HANDLE_T
  526. #define POOL_HANDLE_T
  527. typedef void *pool_handle_t;
  528. #endif
  529.  
  530. #ifndef SEMAPHORE_T
  531. typedef void *SEMAPHORE;
  532. #define SEMAPHORE_T void *
  533. #endif /* !SEMAPHORE_T */
  534.  
  535. #define SESSION_HASHSIZE 5
  536.  
  537. typedef struct PListStruct_s PListStruct_s;
  538. typedef struct ACLListHandle ACLListHandle;
  539.  
  540. typedef struct Session {
  541.     /* Client-specific information */
  542.     pblock *client;
  543.  
  544.     SYS_NETFD csd;
  545.     netbuf *inbuf;
  546.     int csd_open;
  547.  
  548.     struct in_addr iaddr;
  549.  
  550. #ifdef MCC_PROXY
  551.     int req_cnt;
  552. #endif
  553.  
  554. #ifdef MALLOC_POOLS
  555.     pool_handle_t *pool;
  556. #endif /* MALLOC_POOLS */
  557.  
  558.     void *clauth;        /* ACL client authentication information */
  559.     struct Session *next;
  560.     int fill;
  561.     struct sockaddr_in local_addr;   /* local addr for this session*/
  562.  
  563.     PListStruct_s *subject;
  564. } Session;
  565.  
  566. #if defined (SHMEM_UNIX_MMAP) || defined (SHMEM_WIN32_MMAP)
  567. typedef struct {
  568.     void *data;   /* the data */
  569. #ifdef SHMEM_WIN32_MMAP
  570.     HANDLE fdmap;
  571. #endif /* SHMEM_WIN32_MMAP */
  572.     int size;     /* the maximum length of the data */
  573.  
  574.     char *name;   /* internal use: filename to unlink if exposed */
  575.     SYS_FILE fd;  /* internal use: file descriptor for region */
  576. } shmem_s;
  577. #endif  /* SHMEM_UNIX_MMAP || SHMEM_WIN32_MMAP */
  578.  
  579.  
  580. /* Define a handle for a thread */
  581. typedef void* SYS_THREAD;
  582.  
  583. /* Define an error value for the thread handle */
  584. #define SYS_THREAD_ERROR NULL
  585.  
  586. /*
  587.  * Hierarchy of httpd_object
  588.  *
  589.  * An object contains dtables. 
  590.  * 
  591.  * Each dtable is a table of directives that were entered of a certain type.
  592.  * There is one dtable for each unique type of directive.
  593.  *
  594.  * Each dtable contains an array of directives, each of which is equivalent
  595.  * to one directive that occurred in a config. file.
  596.  *
  597.  * It is up to the caller to determine how many dtables will be allocated
  598.  * and to keep track of which of their directive types maps to which dtable
  599.  * number.
  600.  */
  601.  
  602.  
  603. /*
  604.  * directive is a structure containing the protection and parameters to an
  605.  * instance of a directive within an httpd_object.
  606.  *
  607.  * param is the parameters, client is the protection.
  608.  */
  609.  
  610. typedef struct {
  611.     pblock *param;
  612.     pblock *client;
  613. } directive;
  614.  
  615. /*
  616.  * dtable is a structure for creating tables of directives
  617.  */
  618.  
  619. typedef struct {
  620.     int ni;
  621.     directive *inst;
  622. } dtable;
  623.  
  624. /*
  625.  * The httpd_object structure.
  626.  *
  627.  * The name pblock array contains the names for this object, such as its
  628.  * virtual location, its physical location, or its identifier.
  629.  * 
  630.  * tmpl contains any templates allocated to this object.
  631.  */
  632.  
  633. typedef struct {
  634.     pblock *name;
  635.  
  636.     int nd;
  637.     dtable *dt;
  638. } httpd_object;
  639.  
  640. /*
  641.  * httpd_objset is a container for a bunch of objects. obj is a 
  642.  * NULL-terminated array of objects. pos points to the entry after the last
  643.  * one in the array. You should not mess with pos, but can read it to find
  644.  * the last entry.
  645.  *
  646.  * The initfns array is a NULL-terminated array of the Init functions 
  647.  * associated with this object set. If there are no Init functions associated
  648.  * with this object set, initfns can be NULL. Each pblock specifies the
  649.  * parameters which are passed to the function when it's executed.
  650.  */
  651.  
  652. typedef struct {
  653.     int pos;
  654.     httpd_object **obj;
  655.  
  656.     pblock **initfns;
  657. } httpd_objset;
  658.  
  659.  
  660. typedef struct {
  661.  
  662.     /* What port we listen to */
  663.     int Vport;
  664. #define server_portnum conf_getglobals()->Vport
  665.  
  666.     /* What address to bind to */
  667.     char *Vaddr;
  668.  
  669.     /* User to run as */
  670. #define userpw conf_getglobals()->Vuserpw
  671.     struct passwd *Vuserpw;
  672.  
  673.     /* Directory to chroot to */
  674.     char *Vchr;
  675.  
  676.     /* Where to log our pid to */
  677.     char *Vpidfn;
  678.  
  679. #define pool_max conf_getglobals()->Vpool_max
  680.     int Vpool_max;                              /* OBSOLETE */
  681. #define pool_min conf_getglobals()->Vpool_min
  682.     int Vpool_min;                              /* OBSOLETE */
  683. #define pool_life conf_getglobals()->Vpool_life
  684.     int Vpool_life;                             /* OBSOLETE */
  685.  
  686.     /* For multiprocess UNIX servers, the maximum threads per process */
  687. #define pool_maxthreads conf_getglobals()->Vpool_maxthreads
  688.     int Vpool_maxthreads;
  689.  
  690. #define pool_minthreads conf_getglobals()->Vpool_minthreads
  691.     int Vpool_minthreads;                       /* OBSOLETE */
  692.  
  693.     char *Vsecure_keyfn;
  694.     char *Vsecure_certfn;
  695.  
  696. #define security_active conf_getglobals()->Vsecurity_active
  697.     int Vsecurity_active;
  698. #define ssl3_active conf_getglobals()->Vssl3_active
  699.     int Vssl3_active;
  700. #define ssl2_active conf_getglobals()->Vssl2_active
  701.     int Vssl2_active;
  702.     int Vsecure_auth;
  703. #define security_session_timeout conf_getglobals()->Vsecurity_session_timeout
  704.     int Vsecurity_session_timeout;
  705. #define ssl3_session_timeout conf_getglobals()->Vssl3_session_timeout
  706.     long Vssl3_session_timeout;
  707.  
  708.     /* The server's hostname as should be reported in self-ref URLs */
  709. #define server_hostname conf_getglobals()->Vserver_hostname
  710.     char *Vserver_hostname;
  711.  
  712.     /* The main object from which all are derived */
  713. #define root_object conf_getglobals()->Vroot_object
  714.     char *Vroot_object;
  715.  
  716.     /* The object set the administrator has asked us to load */
  717. #define std_os conf_getglobals()->Vstd_os
  718.     httpd_objset *Vstd_os;
  719.  
  720.     /* The root of ACL data structures */
  721.     void *Vacl_root;
  722. #define acl_root conf_getglobals()->Vacl_root
  723.  
  724.     /* The main error log, where all errors are logged */
  725. #define master_error_log conf_getglobals()->Vmaster_error_log
  726.     char *Vmaster_error_log;
  727.  
  728.     /* The server root ( in which the server sits while executing ) */
  729. #define server_root conf_getglobals()->Vserver_root
  730.     char *Vserver_root;
  731.  
  732.     /* This server's id */
  733. #define server_id conf_getglobals()->Vserver_id
  734.     char *Vserver_id;
  735.  
  736.     int single_accept;        /* daemon mode  Internal use only */
  737.     int num_keep_alives;    /* number of KA threads Internal use only */
  738.     int log_verbose;        /* Flag to log LOG_VERBOSE messages */
  739.     int mmap_flags;        /* mmap flags for file cache mmaping - internal use only */
  740.     int mmap_prots;        /* mmap prots for file cache mmaping - internal use only */
  741.     int unused1;
  742.     int unused2;
  743.  
  744.     /* Begin Enterprise 3.0 fields */
  745.     int accept_language;       /* turn accept-language on/off */
  746.  
  747.     char *mtahost;              /* Hostname of the Mail Transport Agent :
  748.                  * typically "localhost" for the Unix boxes,
  749.                  * or the hostname of a POP server otherwise.
  750.                  * Needed by the Agents subsystem.
  751.                  */
  752.     char *nntphost;              /* NNTP server -> for Agents */
  753.  
  754.     /* The root of ACL data structures */
  755.     void *Vacl_root_30;
  756. #define acl_root_30 conf_getglobals()->Vacl_root_30
  757.  
  758.     /* This is for the agent subsystem */
  759.     /* The name of tha configuration parameter is: "AgentsFilePath" */
  760.     char*    agentFilePath; /* path to agent.conf */
  761. #define AgentFilePath (conf_getglobals()->agentFilePath)
  762.  
  763.     /* Default allowed methods - */
  764.     int Allowed;
  765. #define AllowedMethods (conf_getglobals()->Allowed)
  766.  
  767.     pblock *genericGlobals;    /* See conf_api.h for details on accessing 
  768.                                 * these 
  769.                                 */
  770.  
  771.     /*Agents ACL file */
  772.     char* agentsACLFile;
  773.     int wait_for_cgi;
  774.     int cgiwatch_timeout;
  775. } conf_global_vars_s;
  776.  
  777. typedef struct {
  778.     /* Server working variables */
  779.     pblock *vars;
  780.  
  781.     /* The method, URI, and protocol revision of this request */
  782.     pblock *reqpb;
  783.     /* Protocol specific headers */
  784.     int loadhdrs;
  785.     pblock *headers;
  786.  
  787.     /* Server's response headers */
  788.     int senthdrs;
  789.     pblock *srvhdrs;
  790.  
  791.     /* The object set constructed to fulfill this request */
  792.     httpd_objset *os;
  793.     /* Array of objects that were created from .nsconfig files */
  794.     httpd_objset *tmpos;
  795.  
  796.     /* The stat last returned by request_stat_path */
  797.     char *statpath;
  798.     char *staterr;
  799.     struct stat *finfo;
  800.  
  801.     /* access control state */
  802.     int aclstate;        /* ACL decision state */
  803.     int acldirno;        /* deciding ACL directive number */
  804.     char * aclname;        /* name of deciding ACL */
  805.     pblock * aclpb;        /* parameter block for ACL PathCheck */
  806.     /* 3.0 ACL list pointer */
  807.     ACLListHandle *acllist;
  808.  
  809. #ifdef MCC_PROXY
  810.     struct hostent *hp;    /* proxy NSAPI: DNS resolution result */
  811.     char * host;    /* proxy NSAPI: host to resolve/connect to */
  812.     int    port;    /* proxy NSAPI: port to connect to */
  813.  
  814.     void * socks_rq;    /* SOCKS request data */
  815. #endif
  816.  
  817.     int request_is_cacheable;  /* default TRUE */
  818.     int directive_is_cacheable; /* default FALSE */
  819.  
  820.     char *cached_headers;
  821.     int cached_headers_len;    /* length of the valid headers */
  822.     char *unused;
  823.  
  824.     /* HTTP/1.1 features */
  825.     time_t    req_start;    /* Time request arrived - used for determining weak or*/
  826.                         /* strong cache validation */
  827. #define REQ_TIME(x)        (x)->req_start
  828.     short protv_num;        /* Protocol Version number */
  829.     short method_num;        /* Method number */
  830.     struct rq_attr {
  831. #ifdef AIX
  832.         unsigned abs_uri:1;    /* 1=Absolute URI was used */
  833.         unsigned chunked:1;    /* chunked transfer-coding */
  834.         unsigned keep_alive:1;    /* connection keek-alive */
  835.         unsigned pipelined:1;    /* request packet is pipelined */
  836.         unsigned reserved:28;    /* If you add a bit flag, make */
  837.                         /* sure to subtract one from this */
  838. #else
  839.         unsigned long abs_uri:1;    /* 1=Absolute URI was used */
  840.         unsigned long chunked:1;    /* chunked transfer-coding */
  841.         unsigned long keep_alive:1;    /* connection keek-alive */
  842.         unsigned pipelined:1;        /* request packet is pipelined */
  843.         unsigned long reserved:28;    /* If you add a bit flag, make */
  844.                         /* sure to subtract one from this */
  845. #endif
  846.     }rq_attr;
  847.     char * hostname;            /* Not NULL if abs_uri */
  848.     int allowed;                /* Allowed METHODs for this server */
  849.     int byterange;                /* number of byte ranges */
  850.     short status_num;            /* Status code */
  851.  
  852.     int staterrno; /* used for rqstat */
  853. } Request;
  854.  
  855. /* Request attribute macros */
  856. #define ABS_URI(x)         (x)->rq_attr.abs_uri
  857. #define CHUNKED(x)         (x)->rq_attr.chunked
  858. #define KEEP_ALIVE(x)     (x)->rq_attr.keep_alive 
  859. #define PIPELINED(x)     (x)->rq_attr.pipelined 
  860.  
  861. /* Define METHODS for HTTP/1.1 */
  862. #define METHOD_HEAD        0
  863. #define METHOD_GET         1
  864. #define METHOD_PUT        2
  865. #define METHOD_POST     3
  866. #define    METHOD_DELETE    4
  867. #define METHOD_TRACE    5
  868. #define METHOD_OPTIONS    6
  869. /* The following methods are Netscape method extensions */
  870. #define    METHOD_MOVE        7
  871. #define METHOD_INDEX    8
  872. #define METHOD_MKDIR    9
  873. #define METHOD_RMDIR    10
  874. #define METHOD_COPY        11
  875. #define    METHOD_MAX        12    /* Number of methods available on this server */
  876.  
  877. #define ISMGET(r)        ((r)->method_num == METHOD_GET)
  878. #define ISMHEAD(r)        ((r)->method_num == METHOD_HEAD)
  879. #define ISMPUT(r)        ((r)->method_num == METHOD_PUT)
  880. #define ISMPOST(r)        ((r)->method_num == METHOD_POST)
  881. #define ISMDELETE(r)    ((r)->method_num == METHOD_DELETE)
  882. #define ISMMOVE(r)        ((r)->method_num == METHOD_MOVE)
  883. #define ISMINDEX(r)        ((r)->method_num == METHOD_INDEX)
  884. #define ISMMKDIR(r)        ((r)->method_num == METHOD_MKDIR)
  885. #define ISMRMDIR(r)        ((r)->method_num == METHOD_RMDIR)
  886. #define ISMCOPY(r)        ((r)->method_num == METHOD_COPY)
  887. #define ISMTRACE(r)     ((r)->method_num == METHOD_TRACE)
  888. #define ISMOPTIONS(r)   ((r)->method_num == METHOD_OPTIONS)
  889.  
  890. /*
  891.  * FuncPtr is a pointer to our kind of functions
  892.  */
  893.  
  894. #ifdef XP_UNIX
  895. typedef int Func(pblock *, Session *, Request *);
  896. #else /* XP_WIN32 */
  897. typedef int _cdecl Func(pblock *, Session *, Request *);
  898. #endif /* XP_WIN32 */
  899.  
  900. typedef Func *FuncPtr;
  901.  
  902. /*
  903.  * FuncStruct is a structure used in the static declaration of the 
  904.  * functions. This static declaration is parsed into a hash table at 
  905.  * startup. You should initialize the next entry to NULL.
  906.  */
  907.  
  908. struct FuncStruct {
  909.     char *name;
  910.     FuncPtr func;
  911.     struct FuncStruct *next;
  912.     int flags;
  913. };
  914.  
  915. /* --- End type definitions --- */
  916.  
  917. /* --- Begin dispatch vector table definition --- */
  918.  
  919. typedef struct nsapi_dispatch_s nsapi_dispatch_t;
  920. struct nsapi_dispatch_s {
  921.     char *(*f_system_version)();
  922.     void *(*f_system_malloc)(int size);
  923.     void *(*f_system_calloc)(int size);
  924.     void *(*f_system_realloc)(void *ptr, int size);
  925.     void (*f_system_free)(void *ptr);
  926.     char *(*f_system_strdup)(const char *ptr);
  927.     void *(*f_system_malloc_perm)(int size);
  928.     void *(*f_system_calloc_perm)(int size);
  929.     void *(*f_system_realloc_perm)(void *ptr, int size);
  930.     void (*f_system_free_perm)(void *ptr);
  931.     char *(*f_system_strdup_perm)(const char *ptr);
  932.     int (*f_getThreadMallocKey)(void);
  933.     void (*f_magnus_atrestart)(void (*fn)(void *), void *data);
  934.     filebuf_t *(*f_filebuf_open)(SYS_FILE fd, int sz);
  935.     netbuf *(*f_netbuf_open)(SYS_NETFD sd, int sz);
  936.     filebuf_t *(*f_filebuf_create)(SYS_FILE fd, caddr_t mmap_ptr,
  937.                                    int mmap_len, int bufsz);
  938.     void (*f_filebuf_close_buffer)(filebuf_t *buf, int clean_mmap);
  939. #ifdef FILE_MMAP
  940.     filebuf_t *(*f_filebuf_open_nostat)(SYS_FILE fd, int sz,
  941.                                         struct stat *finfo);
  942. #else
  943.     void *(*f_filebuf_open_nostat)(void);
  944. #endif
  945. #ifdef XP_WIN32
  946.     filebuf_t *(*f_pipebuf_open)(SYS_FILE fd, int sz, struct stat *finfo);
  947. #else
  948.     void *(*f_pipebuf_open)(void);
  949. #endif /* XP_WIN32 */
  950. #ifndef FILE_MMAP
  951.     int (*f_filebuf_next)(filebuf_t *buf, int advance);
  952. #else
  953.     int (*f_filebuf_next)(void);
  954. #endif /* !FILE_MMAP */
  955.     int (*f_netbuf_next)(netbuf *buf, int advance);
  956. #ifdef XP_WIN32 
  957.     int (*f_pipebuf_next)(filebuf_t *buf, int advance);
  958. #else
  959.     int (*f_pipebuf_next)(void);
  960. #endif /* XP_WIN32 */
  961.     void (*f_filebuf_close)(filebuf_t *buf);
  962.     void (*f_netbuf_close)(netbuf *buf);
  963. #ifdef XP_WIN32
  964.     void    (*f_pipebuf_close)(filebuf_t *buf);
  965. #else
  966.     void (*f_pipebuf_close)(void);
  967. #endif /* XP_WIN32 */
  968.     int (*f_filebuf_grab)(filebuf_t *buf, int sz);
  969.     int (*f_netbuf_grab)(netbuf *buf, int sz);
  970. #ifdef XP_WIN32
  971.     int (*f_pipebuf_grab)(filebuf_t *buf, int sz);
  972. #else
  973.     int (*f_pipebuf_grab)(void);
  974. #endif /* XP_WIN32 */
  975.     int (*f_netbuf_buf2sd)(netbuf *buf, SYS_NETFD sd, int len);
  976.     int (*f_filebuf_buf2sd)(filebuf_t *buf, SYS_NETFD sd);
  977. #ifdef XP_WIN32
  978.     int (*f_pipebuf_buf2sd)(filebuf_t *buf, SYS_NETFD sd, int len);
  979.     int (*f_pipebuf_netbuf2sd)(netbuf *buf, SYS_FILE sd, int len);
  980.     int (*f_pipebuf_netbuf2pipe)(netbuf *buf, SYS_NETFD sd, int len);
  981. #else
  982.     int (*f_pipebuf_buf2sd)(void);
  983.     int (*f_pipebuf_netbuf2sd)(void);
  984.     int (*f_pipebuf_netbuf2pipe)(void);
  985. #endif /* XP_WIN32 */
  986.     void (*f_cinfo_init)(void);
  987.     void (*f_cinfo_terminate)(void);
  988.     char *(*f_cinfo_merge)(char *fn);
  989.     cinfo *(*f_cinfo_find)(char *uri);
  990.     cinfo *(*f_cinfo_lookup)(char *type);
  991.     void (*f_cinfo_dump_database)(FILE *dump);
  992.     CRITICAL (*f_crit_init)(void);
  993.     void (*f_crit_enter)(CRITICAL id);
  994.     void (*f_crit_exit)(CRITICAL id);
  995.     void (*f_crit_terminate)(CRITICAL id);
  996.     CONDVAR (*f_condvar_init)(CRITICAL id);
  997.     void (*f_condvar_wait)(CONDVAR cv);
  998.     void (*f_condvar_notify)(CONDVAR cv);
  999.     void (*f_condvar_notifyAll)(CONDVAR cv);
  1000.     void (*f_condvar_terminate)(CONDVAR cv);
  1001.     COUNTING_SEMAPHORE (*f_cs_init)(int initial_count);
  1002.     void (*f_cs_terminate)(COUNTING_SEMAPHORE csp);
  1003.     int (*f_cs_wait)(COUNTING_SEMAPHORE csp);
  1004.     int (*f_cs_trywait)(COUNTING_SEMAPHORE csp);
  1005.     int (*f_cs_release)(COUNTING_SEMAPHORE csp);
  1006.     void (*f_daemon_atrestart)(void (*fn)(void *), void *data);
  1007.     void (*f_servssl_init)(char *keyfn, char *certfn, int stimeout,
  1008.                            long ssl3timeout, char *servid);
  1009.     int (*f_ereport)(int degree, char *fmt, ...);
  1010.     int (*f_ereport_v)(int degree, char *fmt, va_list args);
  1011.     char *(*f_ereport_init)(char *err_fn, char *email,
  1012.                             PASSWD pwuser, char *version);
  1013.     void (*f_ereport_terminate)(void);
  1014.     SYS_FILE (*f_ereport_getfd)(void);
  1015.     SYS_FILE (*f_system_fopenRO)(char *path);
  1016.     SYS_FILE (*f_system_fopenWA)(char *path);
  1017.     SYS_FILE (*f_system_fopenRW)(char *path);
  1018.     SYS_FILE (*f_system_fopenWT)(char *path);
  1019.     int (*f_system_fread)(SYS_FILE fd, char *buf, int sz);
  1020.     int (*f_system_fwrite)(SYS_FILE fd,char *buf,int sz);
  1021.     int (*f_system_fwrite_atomic)(SYS_FILE fd, char *buf, int sz);
  1022.     int (*f_system_lseek)(SYS_FILE fd, int off, int wh);
  1023.     int (*f_system_fclose)(SYS_FILE fd);
  1024.     int (*f_system_stat)(char *name, struct stat *finfo);
  1025.     int (*f_system_rename)(char *oldpath, char *newpath);
  1026.     int (*f_system_unlink)(char *path);
  1027.     int (*f_system_tlock)(SYS_FILE fd);
  1028.     int (*f_system_flock)(SYS_FILE fd);
  1029.     int (*f_system_ulock)(SYS_FILE fd);
  1030. #ifdef XP_WIN32
  1031.     SYS_DIR (*f_dir_open)(char *path);
  1032.     SYS_DIRENT *(*f_dir_read)(SYS_DIR ds);
  1033.     void (*f_dir_close)(SYS_DIR ds);
  1034. #else
  1035.     void *(*f_dir_open)(void);
  1036.     void *(*f_dir_read)(void);
  1037.     void (*f_dir_close)(void);
  1038. #endif /* XP_WIN32 */
  1039.     int (*f_dir_create_all)(char *dir);
  1040. #ifdef XP_WIN32
  1041.     char *(*f_system_winsockerr)(void);
  1042.     char *(*f_system_winerr)(void);
  1043.     int (*f_system_pread)(SYS_FILE fd, char *buf, int sz);
  1044.     int (*f_system_pwrite)(SYS_FILE fd, char *buf, int sz);
  1045.     void (*f_file_unix2local)(char *path, char *p2);
  1046. #else
  1047.     void *(*f_system_winsockerr)(void);
  1048.     void *(*f_system_winerr)(void);
  1049.     int (*f_system_pread)(void);
  1050.     int (*f_system_pwrite)(void);
  1051.     void (*f_file_unix2local)(void);
  1052. #endif /* XP_WIN32 */
  1053.     int (*f_system_nocoredumps)(void);
  1054.     int (*f_file_setinherit)(SYS_FILE fd, int value);
  1055.     int (*f_file_notfound)(void);
  1056.     char *(*f_system_errmsg)(void);
  1057.     int (*f_system_errmsg_fn)(char **buff, size_t maxlen);
  1058.     SYS_NETFD (*f_net_socket)(int domain, int type, int protocol);
  1059.     int (*f_net_listen)(SYS_NETFD s, int backlog);
  1060.     SYS_NETFD (*f_net_create_listener)(char *ipaddr, int port);
  1061.     int (*f_net_connect)(SYS_NETFD s, const void *sockaddr, int namelen);
  1062.     int (*f_net_getpeername)(SYS_NETFD s, struct sockaddr *name, int *namelen);
  1063.     int (*f_net_close)(SYS_NETFD s);
  1064.     int (*f_net_bind)(SYS_NETFD s, const struct sockaddr *name, int namelen);
  1065.     SYS_NETFD (*f_net_accept)(SYS_NETFD s, struct sockaddr *addr, int *addrlen);
  1066.     int (*f_net_read)(SYS_NETFD sd, char *buf, int sz, int timeout);
  1067.     int (*f_net_write)(SYS_NETFD sd, char *buf, int sz);
  1068.     int (*f_net_writev)(SYS_NETFD sd, struct iovec *iov, int iovlen);
  1069.     int (*f_net_isalive)(SYS_NETFD sd);
  1070.     char *(*f_net_ip2host)(char *ip, int verify);
  1071.     int (*f_net_getsockopt)(SYS_NETFD s, int level, int optname,
  1072.                             void *optval, int *optlen);
  1073.     int (*f_net_setsockopt)(SYS_NETFD s, int level, int optname,
  1074.                             const void *optval, int optlen);
  1075.     int (*f_net_select)(int nfds, fd_set *r, fd_set *w, fd_set *e, 
  1076.                         struct timeval *timeout);
  1077.     int (*f_net_ioctl)(SYS_NETFD s, int tag, void *result);
  1078.     pb_param *(*f_param_create)(char *name, char *value);
  1079.     int (*f_param_free)(pb_param *pp);
  1080.     pblock *(*f_pblock_create)(int n);
  1081.     void (*f_pblock_free)(pblock *pb);
  1082.     char *(*f_pblock_findval)(const char *name, pblock *pb);
  1083.     pb_param *(*f_pblock_nvinsert)(const char *name, const char *value, pblock *pb);
  1084.     pb_param *(*f_pblock_nninsert)(const char *name, int value, pblock *pb);
  1085.     void (*f_pblock_pinsert)(pb_param *pp, pblock *pb);
  1086.     int (*f_pblock_str2pblock)(const char *str, pblock *pb);
  1087.     char *(*f_pblock_pblock2str)(pblock *pb, char *str);
  1088.     void (*f_pblock_copy)(pblock *src, pblock *dst);
  1089.     pblock *(*f_pblock_dup)(pblock *src);
  1090.     char **(*f_pblock_pb2env)(pblock *pb, char **env);
  1091.     pb_param *(*f_pblock_fr)(const char *name, pblock *pb, int remove);
  1092.     char * (*f_pblock_replace)(const char *name,char * new_value,pblock *pb);
  1093.     pool_handle_t *(*f_pool_create)(void);
  1094.     void (*f_pool_destroy)(pool_handle_t *pool_handle);
  1095.     int (*f_pool_enabled)(void);
  1096.     void *(*f_pool_malloc)(pool_handle_t *pool_handle, size_t size );
  1097.     void (*f_pool_free)(pool_handle_t *pool_handle, void *ptr );
  1098.     void *(*f_pool_calloc)(pool_handle_t *pool_handle, size_t nelem, size_t elsize);
  1099.     void *(*f_pool_realloc)(pool_handle_t *pool_handle, void *ptr, size_t size );
  1100.     char *(*f_pool_strdup)(pool_handle_t *pool_handle, const char *orig_str );
  1101. #if defined(MCC_PROXY) && defined(USE_REGEX)
  1102.     int (*f_regexp_valid)(char *exp);
  1103.     int (*f_regexp_match)(char *str, char *exp);
  1104.     int (*f_regexp_cmp)(char *str, char *exp);
  1105.     int (*f_regexp_casecmp)(char *str, char *exp);
  1106. #else
  1107.     int (*f_regexp_valid)(void);
  1108.     int (*f_regexp_match)(void);
  1109.     int (*f_regexp_cmp)(void);
  1110.     int (*f_regexp_casecmp)(void);
  1111. #endif
  1112.     SEMAPHORE (*f_sem_init)(char *name, int number);
  1113.     void (*f_sem_terminate)(SEMAPHORE id);
  1114.     int (*f_sem_grab)(SEMAPHORE id);
  1115.     int (*f_sem_tgrab)(SEMAPHORE id);
  1116.     int (*f_sem_release)(SEMAPHORE id);
  1117.     Session *(*f_session_alloc)(SYS_NETFD csd, struct sockaddr_in *sac); /* internal */
  1118.     Session *(*f_session_fill)(Session *sn); /* internal */
  1119.     Session *(*f_session_create)(SYS_NETFD csd, struct sockaddr_in *sac);
  1120.     void (*f_session_free)(Session *sn);
  1121.     char *(*f_session_dns_lookup)(Session *sn, int verify);
  1122.     int (*f_shexp_valid)(char *exp);
  1123.     int (*f_shexp_match)(char *str, char *exp);
  1124.     int (*f_shexp_cmp)(char *str, char *exp);
  1125.     int (*f_shexp_casecmp)(char *str, char *exp);
  1126. #if defined (SHMEM_UNIX_MMAP) || defined (SHMEM_WIN32_MMAP)
  1127.     shmem_s *(*f_shmem_alloc)(char *name, int size, int expose);
  1128.     void (*f_shmem_free)(shmem_s *region);
  1129. #else
  1130.     void *(*f_shmem_alloc)(void);
  1131.     void (*f_shmem_free)(void);
  1132. #endif  /* SHMEM_UNIX_MMAP || SHMEM_WIN32_MMAP */
  1133.     SYS_THREAD (*f_systhread_start)(int prio, int stksz, void (*fn)(void *), void *arg);
  1134.     SYS_THREAD (*f_systhread_current)(void);
  1135.     void (*f_systhread_yield)(void);
  1136.     SYS_THREAD (*f_systhread_attach)(void);
  1137.     void (*f_systhread_detach)(SYS_THREAD thr);
  1138.     void (*f_systhread_terminate)(SYS_THREAD thr);
  1139.     void (*f_systhread_sleep)(int milliseconds);
  1140.     void (*f_systhread_init)(char *name);
  1141.     void (*f_systhread_timerset)(int usec);
  1142.     int (*f_systhread_newkey)(void);
  1143.     void *(*f_systhread_getdata)(int key);
  1144.     void (*f_systhread_setdata)(int key, void *data);
  1145.     void (*f_systhread_set_default_stacksize)(unsigned long size);
  1146.     int (*f_util_getline)(filebuffer *buf, int lineno, int maxlen, char *l);
  1147.     char **(*f_util_env_create)(char **env, int n, int *pos);
  1148.     char *(*f_util_env_str)(char *name, char *value);
  1149.     void (*f_util_env_replace)(char **env, char *name, char *value);
  1150.     void (*f_util_env_free)(char **env);
  1151.     char **(*f_util_env_copy)(char **src, char **dst);
  1152.     char *(*f_util_env_find)(char **env, char *name);
  1153.     char *(*f_util_hostname)(void);
  1154.     int (*f_util_chdir2path)(char *path);
  1155.     int (*f_util_is_mozilla)(char *ua, char *major, char *minor);
  1156.     int (*f_util_is_url)(char *url);
  1157.     int (*f_util_later_than)(struct tm *lms, char *ims);
  1158.     int (*f_util_time_equal)(struct tm *lms, char *ims);
  1159.     int (*f_util_str_time_equal)(char *t1, char *t2);
  1160.     int (*f_util_uri_is_evil)(char *t);
  1161.     void (*f_util_uri_parse)(char *uri);
  1162.     void (*f_util_uri_unescape)(char *s);
  1163.     char *(*f_util_uri_escape)(char *d, char *s);
  1164.     char *(*f_util_url_escape)(char *d, char *s);
  1165.     char *(*f_util_sh_escape)(char *s);
  1166.     int (*f_util_mime_separator)(char *sep);
  1167.     int (*f_util_itoa)(int i, char *a);
  1168.     int (*f_util_vsprintf)(char *s, register const char *fmt, va_list args);
  1169.     int (*f_util_sprintf)(char *s, const char *fmt, ...);
  1170.     int (*f_util_vsnprintf)(char *s, int n, register const char *fmt, 
  1171.                             va_list args);
  1172.     int (*f_util_snprintf)(char *s, int n, const char *fmt, ...);
  1173.     int (*f_util_strftime)(char *s, const char *format, const struct tm *t);
  1174.     char *(*f_util_strtok)(char *s1, const char *s2, char **lasts);
  1175.     struct tm *(*f_util_localtime)(const time_t *clock, struct tm *res);
  1176.     char *(*f_util_ctime)(const time_t *clock, char *buf, int buflen);
  1177.     char *(*f_util_strerror)(int errnum, char *msg, int buflen);
  1178.     struct tm *(*f_util_gmtime)(const time_t *clock, struct tm *res);
  1179.     char *(*f_util_asctime)(const struct tm *tm,char *buf, int buflen);
  1180. #ifdef NEED_STRCASECMP
  1181.     int (*f_util_strcasecmp)(CASECMPARG_T char *one, CASECMPARG_T char *two);
  1182. #else
  1183.     int (*f_util_strcasecmp)(void);
  1184. #endif /* NEED_STRCASECMP */
  1185. #ifdef NEED_STRNCASECMP
  1186.     int (*f_util_strncasecmp)(CASECMPARG_T char *one, CASECMPARG_T char *two, int n);
  1187. #else
  1188.     int (*f_util_strncasecmp)(void);
  1189. #endif /* NEED_STRNCASECMP */
  1190. #ifdef XP_UNIX
  1191.     int (*f_util_can_exec)(struct stat *finfo, uid_t uid, gid_t gid);
  1192.     struct passwd *(*f_util_getpwnam)(const char *name, struct passwd
  1193.                                       *result, char *buffer,  int buflen);
  1194.     pid_t (*f_util_waitpid)(pid_t pid, int *statptr, int options);
  1195. #else
  1196.     int (*f_util_can_exec)(void);
  1197.     void *(*f_util_getpwnam)(void);
  1198.     int (*f_util_waitpid)(void);
  1199. #endif /* XP_UNIX */
  1200. #ifdef XP_WIN32
  1201.     VOID (*f_util_delete_directory)(char *FileName, BOOL delete_directory);
  1202. #else
  1203.     void (*f_util_delete_directory)(void);
  1204. #endif /* XP_WIN32 */
  1205.     char *(*f_conf_init)(char *cfn);
  1206.     char *(*f_conf_run_init_functions)(void);
  1207.     void (*f_conf_terminate)(void);
  1208.     conf_global_vars_s *(*f_conf_getglobals)(void);
  1209.     void (*f_func_init)(struct FuncStruct *func_standard);
  1210.     FuncPtr (*f_func_find)(char *name);
  1211.     int (*f_func_exec)(pblock *pb, Session *sn, Request *rq);
  1212.     struct FuncStruct *(*f_func_insert)(char *name, FuncPtr fn);
  1213.     int (*f_object_execute)(directive *inst, Session *sn, void *rq);
  1214.     Request *(*f_http_find_request)(netbuf *buf, Session *sn, int *reply);
  1215.     int (*f_http_parse_request)(char *t, Request *rq, Session *sn);
  1216.     int (*f_http_scan_headers)(Session *sn, netbuf *buf, char *t,
  1217.                                pblock *headers);
  1218.     int (*f_http_start_response)(Session *sn, Request *rq);
  1219.     char **(*f_http_hdrs2env)(pblock *pb);
  1220.     void (*f_http_status)(Session *sn, Request *rq, int n, char *r);
  1221.     int (*f_http_set_finfo)(Session *sn, Request *rq, struct stat *finfo);
  1222.     char *(*f_http_dump822)(pblock *pb, char *t, int *pos, int tsz);
  1223.     void (*f_http_finish_request)(Session *sn, Request *rq);
  1224.     void (*f_http_handle_session)(Session *sn);
  1225.     char *(*f_http_uri2url)(const char *prefix, const char *suffix);
  1226.     char *(*f_http_uri2url_dynamic)(const char *prefix, const char *suffix,
  1227.                                     Session *sn, Request *rq);
  1228.     void (*f_http_set_keepalive_timeout)(int secs);
  1229.     int (*f_log_error_v)(int degree, char *func, Session *sn, Request *rq,
  1230.                          char *fmt, va_list args);
  1231.     int (*f_log_error)(int degree, char *func, Session *sn, Request *rq,
  1232.                        char *fmt, ...);
  1233.     int (*f_log_ereport_v)(int degree, char *fmt, va_list args);
  1234.     int (*f_log_ereport)(int degree, char *fmt, ...);
  1235.     httpd_object *(*f_object_create)(int nd, pblock *name);
  1236.     void (*f_object_free)(httpd_object *obj);
  1237.     void (*f_object_add_directive)(int dc, pblock *p, pblock *c,
  1238.                                    httpd_object *obj);
  1239.     httpd_objset *(*f_objset_scan_buffer)(filebuffer *buf, char *errstr,
  1240.                                           httpd_objset *os);
  1241.     httpd_objset *(*f_objset_create)(void);
  1242.     void (*f_objset_free)(httpd_objset *os);
  1243.     void (*f_objset_free_setonly)(httpd_objset *os);
  1244.     httpd_object *(*f_objset_new_object)(pblock *name, httpd_objset *os);
  1245.     void (*f_objset_add_object)(httpd_object *obj, httpd_objset *os);
  1246.     void (*f_objset_add_init)(pblock *initfn, httpd_objset *os);
  1247.     httpd_object *(*f_objset_findbyname)(char *name, httpd_objset *ign,
  1248.                                          httpd_objset *os);
  1249.     httpd_object *(*f_objset_findbyppath)(char *ppath, httpd_objset *ign,
  1250.                                           httpd_objset *os);
  1251.     Request *(*f_request_create)(void);
  1252.     void (*f_request_free)(Request *req);
  1253.     Request *(*f_request_restart_internal)(char *uri, Request *rq);
  1254.     int (*f_request_header)(char *name, char **value, Session *sn,
  1255.                             Request *rq);
  1256.     struct stat *(*f_request_stat_path)(char *path, Request *rq);
  1257.     char *(*f_conf_getServerString)(void);
  1258.     FuncPtr (*f_func_replace)(char *funcname, FuncPtr fn);
  1259.     int (*f_net_socketpair)(SYS_NETFD *pair);
  1260. #ifdef XP_UNIX
  1261.     SYS_NETFD (*f_net_dup2)(SYS_NETFD prfd, int osfd);
  1262.     int (*f_net_is_STDOUT)(SYS_NETFD prfd);
  1263.     int (*f_net_is_STDIN)(SYS_NETFD prfd);
  1264. #else
  1265.     void *(*f_net_dup2)(void);
  1266.     int (*f_net_is_STDOUT)(void);
  1267.     int (*f_net_is_STDIN)(void);
  1268. #endif /* XP_UNIX */
  1269.     int (*f_func_set_native_thread_flag)(char *name, int flags);
  1270.     void *(*f_random_create)(void);
  1271.     void (*f_random_update)(void *rctx, unsigned char *inbuf, int length);
  1272.     void (*f_random_generate)(void *rctx, unsigned char *outbuf, int length);
  1273.     void (*f_random_destroy)(void *rctx);
  1274.     void *(*f_md5hash_create)(void);
  1275.     void *(*f_md5hash_copy)(void *hctx);
  1276.     void (*f_md5hash_begin)(void *hctx);
  1277.     void (*f_md5hash_update)(void *hctx, unsigned char *inbuf, int length);
  1278.     void (*f_md5hash_end)(void *hctx, unsigned char *outbuf);
  1279.     void (*f_md5hash_destroy)(void *hctx);
  1280.     void (*f_md5hash_data)(unsigned char *outbuf, unsigned char *src, int length);
  1281.     int (*f_ACL_SetupEval)(struct ACLListHandle *acllist, Session *sn, Request *rq, char **rights, char **map_generic, const char *user);
  1282.     int (*f_netbuf_getbytes)(netbuf *buf, char *buffer, int size);
  1283.     char *(*f_servact_translate_uri)(char *uri, Session *sn);
  1284.     
  1285. };
  1286.  
  1287. /* --- End dispatch vector table definition --- */
  1288.  
  1289. /* --- Begin API macro definitions --- */
  1290.  
  1291. #ifndef INTNSAPI
  1292.  
  1293. #define system_version (*__nsapi30_table->f_system_version)
  1294.  
  1295. /*
  1296.    Depending on the system, memory allocated via these macros may come from 
  1297.    an arena. If these functions are called from within an Init function, they 
  1298.    will be allocated from permanent storage. Otherwise, they will be freed 
  1299.    when the current request is finished.
  1300.  */
  1301.  
  1302. #define MALLOC (*__nsapi30_table->f_system_malloc)
  1303. #define system_malloc (*__nsapi30_table->f_system_malloc)
  1304.  
  1305. #define CALLOC (*__nsapi30_table->f_system_calloc)
  1306. #define system_calloc (*__nsapi30_table->f_system_calloc)
  1307.  
  1308. #define REALLOC (*__nsapi30_table->f_system_realloc)
  1309. #define system_realloc (*__nsapi30_table->f_system_realloc)
  1310.  
  1311. #define FREE (*__nsapi30_table->f_system_free)
  1312. #define system_free (*__nsapi30_table->f_system_free)
  1313.  
  1314. #define STRDUP (*__nsapi30_table->f_system_strdup)
  1315. #define system_strdup (*__nsapi30_table->f_system_strdup)
  1316.  
  1317. #ifndef NS_MALLOC_DEBUG
  1318.  
  1319. /*
  1320.    These macros always provide permanent storage, for use in global variables
  1321.    and such. They are checked at runtime to prevent them from returning NULL.
  1322.  */
  1323.  
  1324. #define PERM_MALLOC (*__nsapi30_table->f_system_malloc_perm)
  1325. #define system_malloc_perm (*__nsapi30_table->f_system_malloc_perm)
  1326.  
  1327. #define PERM_CALLOC (*__nsapi30_table->f_system_calloc_perm)
  1328. #define system_calloc_perm (*__nsapi30_table->f_system_calloc_perm)
  1329.  
  1330. #define PERM_REALLOC (*__nsapi30_table->f_system_realloc_perm)
  1331. #define system_realloc_perm (*__nsapi30_table->f_system_realloc_perm)
  1332.  
  1333. #define PERM_FREE (*__nsapi30_table->f_system_free_perm)
  1334. #define system_free_perm (*__nsapi30_table->f_system_free_perm)
  1335.  
  1336. #define PERM_STRDUP (*__nsapi30_table->f_system_strdup_perm)
  1337. #define system_strdup_perm (*__nsapi30_table->f_system_strdup_perm)
  1338.  
  1339. #endif /* !NS_MALLOC_DEBUG */
  1340.  
  1341. /* Thread-Private data key index for accessing the thread-private memory pool.
  1342.  * Each thread creates its own pool for allocating data.  The MALLOC/FREE/etc
  1343.  * macros have been defined to check the thread private data area with the
  1344.  * thread_malloc_key index to find the address for the pool currently in use.
  1345.  *
  1346.  * If a thread wants to use a different pool, it must change the thread-local-
  1347.  * storage[thread_malloc_key].
  1348.  */
  1349.  
  1350. #define getThreadMallocKey (*__nsapi30_table->f_getThreadMallocKey)
  1351.  
  1352. #define magnus_atrestart (*__nsapi30_table->f_magnus_atrestart)
  1353.  
  1354. /*
  1355.  * buffer_open opens a new buffer reading the specified file, with an I/O
  1356.  * buffer of size sz, and returns a new buffer structure which will hold
  1357.  * the data.
  1358.  *
  1359.  * If FILE_UNIX_MMAP is defined, this may return NULL. If it does, check 
  1360.  * system_errmsg to get a message about the error.
  1361.  */
  1362.  
  1363. #define filebuf_open (*__nsapi30_table->f_filebuf_open)
  1364. #define netbuf_open (*__nsapi30_table->f_netbuf_open)
  1365.  
  1366. /*
  1367.  * filebuf_open_nostat is a convenience function for mmap() buffer opens,
  1368.  * if you happen to have the stat structure already.
  1369.  */
  1370.  
  1371. #ifdef FILE_MMAP
  1372. #define filebuf_open_nostat (*__nsapi30_table->f_filebuf_open_nostat)
  1373. #endif /* FILE_MMAP */
  1374.  
  1375. /*
  1376.  * filebuf_create is a convenience function if the file is already open
  1377.  * or mmap'd.  It creates a new filebuf for use with the mmap'd file.
  1378.  * If mmap_ptr is NULL, or MMAP is not supported on this system, it 
  1379.  * creates a buffer with buffer size bufsz.
  1380.  */
  1381.  
  1382. #define filebuf_create (*__nsapi30_table->f_filebuf_create)
  1383.  
  1384. /* 
  1385.  * filebuf_close_buffer is provided to cleanup a filebuf without closing
  1386.  * the underlying file.  If clean_mmap is 1, and the file is memory mapped,
  1387.  * the file will be unmapped.  If clean_mmap is 0, the file will not
  1388.  * be unmapped.
  1389.  */
  1390. #define filebuf_close_buffer (*__nsapi30_table->f_filebuf_close_buffer)
  1391.  
  1392. #ifdef FILE_MMAP
  1393. #define filebuf_open_nostat (*__nsapi30_table->f_filebuf_open_nostat)
  1394. #endif
  1395.  
  1396. #ifdef XP_WIN32
  1397. #define pipebuf_open (*__nsapi30_table->f_pipebuf_open)
  1398. #endif /* XP_WIN32 */
  1399.  
  1400. /*
  1401.  * buffer_next loads size more bytes into the given buffer and returns the
  1402.  * first one, or BUFFER_EOF on EOF and BUFFER_ERROR on error.
  1403.  */
  1404.  
  1405. #ifndef FILE_MMAP
  1406. #define filebuf_next (*__nsapi30_table->f_filebuf_next)
  1407. #endif /* !FILE_MMAP */
  1408. #define netbuf_next (*__nsapi30_table->f_netbuf_next)
  1409. #ifdef XP_WIN32 
  1410. #define pipebuf_next (*__nsapi30_table->f_pipebuf_next)
  1411. #endif /* XP_WIN32 */
  1412.  
  1413. /*
  1414.  * buffer_close deallocates a buffer and closes its associated files
  1415.  * (does not close a network socket).
  1416.  */
  1417.  
  1418. #define filebuf_close (*__nsapi30_table->f_filebuf_close)
  1419. #define netbuf_close (*__nsapi30_table->f_netbuf_close)
  1420. #ifdef XP_WIN32
  1421. #define pipebuf_close (*__nsapi30_table->f_pipebuf_close)
  1422. #endif /* XP_WIN32 */
  1423.  
  1424. /*
  1425.  * buffer_grab will set the buffer's inbuf array to an array of sz bytes 
  1426.  * from the buffer's associated object. It returns the number of bytes 
  1427.  * actually read (between 1 and sz). It returns IO_EOF upon EOF or IO_ERROR
  1428.  * upon error. The cursize entry of the structure will reflect the size
  1429.  * of the iobuf array.
  1430.  * 
  1431.  * The buffer will take care of allocation and deallocation of this array.
  1432.  */
  1433.  
  1434. #define filebuf_grab (*__nsapi30_table->f_filebuf_grab)
  1435. #define netbuf_grab (*__nsapi30_table->f_netbuf_grab)
  1436. #ifdef XP_WIN32
  1437. #define pipebuf_grab (*__nsapi30_table->f_pipebuf_grab)
  1438. #endif /* XP_WIN32 */
  1439.  
  1440. /*
  1441.  * netbuf_getbytes will read bytes from the netbuf into the user
  1442.  * supplied buffer.  Up to size bytes will be read.
  1443.  * If the call is successful, the number of bytes read is returned.  
  1444.  * NETBUF_EOF is returned when no more data will arrive on the socket,
  1445.  * and NETBUF_ERROR is returned in the event of an error.
  1446.  *
  1447.  */
  1448. #define netbuf_getbytes (*__nsapi30_table->f_netbuf_getbytes)
  1449.  
  1450.  
  1451. /*
  1452.  * netbuf_buf2sd will send n bytes from the (probably previously read)
  1453.  * buffer and send them to sd. If sd is -1, they are discarded. If n is
  1454.  * -1, it will continue until EOF is recieved. Returns IO_ERROR on error
  1455.  * and the number of bytes sent any other time.
  1456.  */
  1457.  
  1458. #define netbuf_buf2sd (*__nsapi30_table->f_netbuf_buf2sd)
  1459.  
  1460. /*
  1461.  * filebuf_buf2sd assumes that nothing has been read from the filebuf, 
  1462.  * and just sends the file out to the given socket. Returns IO_ERROR on error
  1463.  * and the number of bytes sent otherwise.
  1464.  *
  1465.  * Does not currently support you having read from the buffer previously. This
  1466.  * can be changed transparently.
  1467.  */
  1468.  
  1469. #define filebuf_buf2sd (*__nsapi30_table->f_filebuf_buf2sd)
  1470.  
  1471. #ifdef XP_WIN32
  1472.  
  1473. /*
  1474.  * NT pipe version of filebuf_buf2sd.
  1475.  */
  1476. #define pipebuf_buf2sd (*__nsapi30_table->f_pipebuf_buf2sd)
  1477.  
  1478. /*
  1479.  * NT pipe version of netbuf_buf2sd.
  1480.  */
  1481.  
  1482. #define pipebuf_netbuf2sd (*__nsapi30_table->f_pipebuf_netbuf2sd)
  1483. #define pipebuf_netbuf2pipe (*__nsapi30_table->f_pipebuf_netbuf2pipe)
  1484. #endif /* XP_WIN32 */
  1485.  
  1486. /*
  1487.  * Notes:
  1488.  *
  1489.  *      Format of a mime.types file
  1490.  *
  1491.  *          A mime.types file passed to cinfo_merge() should begin with
  1492.  *          a line containing NCC_MT_MAGIC as defined below (MCC_MT_MAGIC
  1493.  *          is also still supported).  Lines containing only whitespace
  1494.  *          and lines beginning with "#" are ignored.  Other lines contain
  1495.  *          one or more name/value pairs, separated by whitespace.  The
  1496.  *          format of each of these is NAME=VALUE, where NAME is one of:
  1497.  *
  1498.  *              type - VALUE is a mime type, e.g. text/html
  1499.  *              exts - VALUE is a list of file extensions, e.g. htm,html
  1500.  *              enc - VALUE specifies a content encoding, e.g. x-gzip
  1501.  *              lang - VALUE specifies a content language, e.g. en-US
  1502.  *                      (see RFC1766)
  1503.  *
  1504.  *         The VALUE may be enclosed in quotes (" "), and should be if it
  1505.  *         contains whitespace.
  1506.  *
  1507.  *         Each line in the file that contains at least one name/value
  1508.  *         pair causes a cinfo structure to be created, containing the
  1509.  *         specified information.  These structures are kept in memory
  1510.  *         and can be queried using cinfo_find().
  1511.  *
  1512.  *      Related information
  1513.  *
  1514.  *          See the NSAPI "load-types" function.
  1515.  */
  1516.  
  1517. /*
  1518.  * Function:    cinfo_init
  1519.  *
  1520.  * Description:
  1521.  *
  1522.  *      This function initializes the memory resident content information
  1523.  *      database to be empty.
  1524.  *
  1525.  * Notes:
  1526.  *
  1527.  *      This function is called by the NSAPI "load-types" function,
  1528.  *      which also sets up a call to cinfo_terminate() on server restart.
  1529.  *      If "load-types" is used, it should be unnecessary to call this
  1530.  *      function.
  1531.  */
  1532.  
  1533. #define cinfo_init (*__nsapi30_table->f_cinfo_init)
  1534.  
  1535. /*
  1536.  * Function:    cinfo_terminate
  1537.  *
  1538.  * Description:
  1539.  *
  1540.  *      This function frees all dynamic memory associated with the
  1541.  *      memory resident content information database, and leaves the
  1542.  *      database empty.  cinfo_init() should be called before using
  1543.  *      the database again.
  1544.  */
  1545.  
  1546. #define cinfo_terminate (*__nsapi30_table->f_cinfo_terminate)
  1547.  
  1548. /*
  1549.  * Function:    cinfo_merge
  1550.  *
  1551.  * Description:
  1552.  *
  1553.  *      This function reads a mime.types formatted file of the specified
  1554.  *      name.  Content information in the file is merged into the
  1555.  *      memory resident content information database.
  1556.  *
  1557.  * Arguments:
  1558.  *
  1559.  *      fn              - name of mime.types formatted file
  1560.  *
  1561.  * Returns:
  1562.  *
  1563.  *      If successful, NULL is returned.  If an error occurs, the return
  1564.  *      value is a pointer to a descriptive error string, which should
  1565.  *      be freed by the caller (using FREE()).  Information processed
  1566.  *      prior to the error will still be added to the database.
  1567.  */
  1568.  
  1569. #define cinfo_merge (*__nsapi30_table->f_cinfo_merge)
  1570.  
  1571.  
  1572. /*
  1573.  * Function:    cinfo_find
  1574.  *
  1575.  * Description:
  1576.  *
  1577.  *      This function is used to retrieve content information based on
  1578.  *      a file extension contained in the argument string, which might
  1579.  *      be either a URI or a file name.  It ignores any text up to and
  1580.  *      including the last FILE_PATHSEP character in the argument
  1581.  *      string.  It looks for one or more file extensions in the
  1582.  *      remaining string, each one starting with a CINFO_SEPARATOR
  1583.  *      character.  Each file extension is looked up in the database
  1584.  *      and any information found there is used to build a composite
  1585.  *      cinfo structure, containing information derived from each of
  1586.  *      the file extensions.  If more than one file extensions present
  1587.  *      have a particular piece of information associated with them
  1588.  *      in the database (e.g. type or language), the value returned in
  1589.  *      the composite cinfo structure is taken from the data for the
  1590.  *      last file extension to provide that attribute.
  1591.  *
  1592.  * Arguments:
  1593.  *
  1594.  *      uri             - pointer to the argument string
  1595.  *
  1596.  * Returns:
  1597.  *
  1598.  *      If successful, a pointer to the composite cinfo structure is
  1599.  *      returned.  The fields of this structure reference values of
  1600.  *      those fields in one or more cinfo structures in the database,
  1601.  *      so these values should be copied if they are going to be
  1602.  *      modified.  The cinfo structure itself should be freed by the
  1603.  *      caller using FREE().  If an error occurs, a null pointer is
  1604.  *      returned.  If no information is found for any of the extensions,
  1605.  *      a null pointer is returned, although this is not necessarily
  1606.  *      an error.
  1607.  *
  1608.  * Notes:
  1609.  *
  1610.  *      The matching of extensions in the argument string to extensions
  1611.  *      in the database is case-insensitive.
  1612.  *
  1613.  *      The argument string is modified during parsing, but only
  1614.  *      temporarily.  It should be intact on return.
  1615.  */
  1616.  
  1617. #define cinfo_find (*__nsapi30_table->f_cinfo_find)
  1618.  
  1619. /*
  1620.  * Function:    cinfo_lookup
  1621.  *
  1622.  * Description:
  1623.  *
  1624.  *      This function returns a pointer to the last cinfo structure
  1625.  *      added to the database for a specified mime type.  Unlike
  1626.  *      cinfo_find(), the returned pointer references a cinfo structure
  1627.  *      that is part of the database, and corresponds to a single line
  1628.  *      in a mime.types file.  This structure should be considered
  1629.  *      read-only, and should not be freed by the caller.
  1630.  *
  1631.  * Arguments:
  1632.  *
  1633.  *      type            - a pointer to a mime type string
  1634.  *
  1635.  * Returns:
  1636.  *
  1637.  *      If the specified type is found, a pointer to the cinfo structure
  1638.  *      returned.  Otherwise a null pointer is returned.
  1639.  *
  1640.  * Notes:
  1641.  *
  1642.  *      The search for the type is case-insensitive.
  1643.  */
  1644.  
  1645. #define cinfo_lookup (*__nsapi30_table->f_cinfo_lookup)
  1646.  
  1647. /*
  1648.  * Function:    cinfo_dump_database
  1649.  *
  1650.  * Description:
  1651.  *
  1652.  *      This function outputs, to a specified file, formatted text
  1653.  *      describing the contents of the content information database.
  1654.  *      This is intended for debugging purposes.  It is not in mime.types
  1655.  *      format.
  1656.  *
  1657.  * Arguments:
  1658.  *
  1659.  *      dump            - handle for already open output file
  1660.  */
  1661.  
  1662. #define cinfo_dump_database (*__nsapi30_table->f_cinfo_dump_database)
  1663.  
  1664. /*
  1665.  *      Critical section abstraction. Used in threaded servers to protect
  1666.  *      areas where two threads can interfere with each other.
  1667.  *
  1668.  *      Condvars are condition variables that are used for thread-thread 
  1669.  *      synchronization.
  1670.  */
  1671.  
  1672. /*
  1673.  * crit_init creates and returns a new critical section variable. At the 
  1674.  * time of creation no one has entered it.
  1675.  */
  1676. #define crit_init (*__nsapi30_table->f_crit_init)
  1677.  
  1678. /*
  1679.  * crit_enter enters a critical section. If someone is already in the
  1680.  * section, the calling thread is blocked until that thread exits.
  1681.  */
  1682. #define crit_enter (*__nsapi30_table->f_crit_enter)
  1683.  
  1684. /*
  1685.  * crit_exit exits a critical section. If another thread is blocked waiting
  1686.  * to enter, it will be unblocked and given ownership of the section.
  1687.  */
  1688. #define crit_exit (*__nsapi30_table->f_crit_exit)
  1689.  
  1690. /*
  1691.  * crit_terminate removes a previously allocated critical section variable.
  1692.  */
  1693. #define crit_terminate (*__nsapi30_table->f_crit_terminate)
  1694.  
  1695. /*
  1696.  * condvar_init initializes and returns a new condition variable. You 
  1697.  * must provide a critical section to be associated with this condition 
  1698.  * variable.
  1699.  */
  1700. #define condvar_init (*__nsapi30_table->f_condvar_init)
  1701.  
  1702. /*
  1703.  * condvar_wait blocks on the given condition variable. The calling thread
  1704.  * will be blocked until another thread calls condvar_notify on this variable.
  1705.  * The caller must have entered the critical section associated with this
  1706.  * condition variable prior to waiting for it.
  1707.  */
  1708. #define condvar_wait (*__nsapi30_table->f_condvar_wait)
  1709.  
  1710. /*
  1711.  * condvar_notify awakens any threads blocked on the given condition
  1712.  * variable. The caller must have entered the critical section associated
  1713.  * with this variable first.
  1714.  */
  1715. #define condvar_notify (*__nsapi30_table->f_condvar_notify)
  1716.  
  1717. /*
  1718.  * condvar_notify awakens all threads blocked on the given condition
  1719.  * variable. The caller must have entered the critical section associated
  1720.  * with this variable first.
  1721.  */
  1722. #define condvar_notifyAll (*__nsapi30_table->f_condvar_notifyAll)
  1723.  
  1724. /*
  1725.  * condvar_terminate frees the given previously allocated condition variable
  1726.  */
  1727. #define condvar_terminate (*__nsapi30_table->f_condvar_terminate)
  1728.  
  1729. /*
  1730.  * Create a counting semaphore.  
  1731.  * Return non-zero on success, 0 on failure.
  1732.  */
  1733. #define cs_init (*__nsapi30_table->f_cs_init)
  1734.  
  1735. /*
  1736.  * Destroy a counting semaphore 
  1737.  */
  1738. #define cs_terminate (*__nsapi30_table->f_cs_terminate)
  1739.  
  1740. /*
  1741.  * Wait to "enter" the semaphore.
  1742.  * Return 0 on success, -1 on failure.
  1743.  */
  1744. #define cs_wait (*__nsapi30_table->f_cs_wait)
  1745.  
  1746. /*
  1747.  * Enter the semaphore if the count is > 0.  Otherwise return -1.
  1748.  *
  1749.  */
  1750. #define cs_trywait (*__nsapi30_table->f_cs_trywait)
  1751.  
  1752. /*
  1753.  * Release the semaphore- allowing a thread to enter.
  1754.  * Return 0 on success, -1 on failure.
  1755.  */
  1756. #define cs_release (*__nsapi30_table->f_cs_release)
  1757.  
  1758. /*
  1759.  * daemon_atrestart registers a function to be called fn, with the given
  1760.  * void pointer as an argument, when the server is restarted.
  1761.  */
  1762. #define daemon_atrestart (*__nsapi30_table->f_daemon_atrestart)
  1763.  
  1764. #define servssl_init (*__nsapi30_table->f_servssl_init)
  1765.  
  1766. /*
  1767.  * ereport logs an error of the given degree and formats the arguments with 
  1768.  * the printf() style fmt. Returns whether the log was successful. Records 
  1769.  * the current date.
  1770.  */
  1771.  
  1772. #define ereport (*__nsapi30_table->f_ereport)
  1773. #define ereport_v (*__nsapi30_table->f_ereport_v)
  1774.  
  1775. /*
  1776.  * ereport_init initializes the error logging subsystem and opens the static
  1777.  * file descriptors. It returns NULL upon success and an error string upon
  1778.  * error. If a userpw is given, the logs will be chowned to that user.
  1779.  * 
  1780.  * email is the address of a person to mail upon catastrophic error. It
  1781.  * can be NULL if no e-mail is desired. ereport_init will not duplicate
  1782.  * its own copy of this string; you must make sure it stays around and free
  1783.  * it when you shut down the server.
  1784.  */
  1785.  
  1786. #define ereport_init (*__nsapi30_table->f_ereport_init)
  1787.  
  1788. /*
  1789.  * log_terminate closes the error and common log file descriptors.
  1790.  */
  1791. #define ereport_terminate (*__nsapi30_table->f_ereport_terminate)
  1792.  
  1793. /* For restarts */
  1794. #define ereport_getfd (*__nsapi30_table->f_ereport_getfd)
  1795.  
  1796. /* FUNCTION: system_fopenXX
  1797.  * DESCRIPTION:
  1798.  *    system_fopenRO - Open a disk file for read-only access.
  1799.  *    system_fopenWA - Open a disk file for write and append access.
  1800.  *    system_fopenRW - Open a disk file for read-write access.
  1801.  *    system_fopenWT - Open a disk file for write and truncate access.
  1802.  * INPUTS:
  1803.  *    path- the name of the file
  1804.  * OUTPUTS:
  1805.  *    none
  1806.  * RETURNS:
  1807.  *    SYS_ERRORFD on failure
  1808.  *    A opaque file handle on success
  1809.  * RESTRICTIONS:
  1810.  *    The return from this function should not be interpreted as a native
  1811.  *    file handle.  It may only be used in other calls to system_xxx().
  1812.  *
  1813.  *    Note for unix programmers: Although this routine is called 
  1814.  *      "system_fopen" do not consider it to be equivalent to the unix 
  1815.  *      "fopen" call, which opens a buffered-IO file.
  1816.  */
  1817. #define system_fopenRO (*__nsapi30_table->f_system_fopenRO)
  1818. #define system_fopenWA (*__nsapi30_table->f_system_fopenWA)
  1819. #define system_fopenRW (*__nsapi30_table->f_system_fopenRW)
  1820. #define system_fopenWT (*__nsapi30_table->f_system_fopenWT)
  1821.  
  1822. /* FUNCTION: system_fread
  1823.  * DESCRIPTION:
  1824.  *    Read from a file
  1825.  * INPUTS:
  1826.  *    fd- an open file handle to read from
  1827.  *    buf- a buffer to receive data
  1828.  *    sz- the number of bytes to read from the file
  1829.  * OUTPUTS:
  1830.  *    none
  1831.  * RETURNS:
  1832.  *    less-than-zero on failure
  1833.  *    0 for end-of-file
  1834.  *    positive for number of bytes read
  1835.  * RESTRICTIONS:
  1836.  */
  1837. #define system_fread (*__nsapi30_table->f_system_fread)
  1838.  
  1839. /* FUNCTION: system_write
  1840.  * DESCRIPTION:
  1841.  *    Writes sz bytes from buf to file fd.  
  1842.  * INPUTS:
  1843.  *    fd- the file to write to
  1844.  *    buf- the buffer containing data to be written
  1845.  *    sz-  the size of data to write.
  1846.  * OUTPUTS:
  1847.  *    none
  1848.  * RETURNS:
  1849.  *    IO_OKAY on success
  1850.  *    IO_ERROR on failure
  1851.  * RESTRICTIONS:
  1852.  *    There is no way to determine if bytes were written when this call fails.
  1853.  *    For more specific information, use PR_WRITE().
  1854.  */
  1855. #define system_fwrite (*__nsapi30_table->f_system_fwrite)
  1856.  
  1857. /* FUNCTION: system_fwrite_atomic
  1858.  * DESCRIPTION:
  1859.  *    system_fwrite_atomic locks the given fd before writing to it. This
  1860.  *    avoids interference between simultaneous writes.
  1861.  * INPUTS:
  1862.  *    fd- the file to write to
  1863.  *    buf- the buffer containing data to be written
  1864.  *    sz-  the size of data to write.
  1865.  * OUTPUTS:
  1866.  *    none
  1867.  * RETURNS:
  1868.  *    IO_OKAY on success
  1869.  *    IO_ERROR on failure
  1870.  * RESTRICTIONS:
  1871.  */
  1872. #define system_fwrite_atomic (*__nsapi30_table->f_system_fwrite_atomic)
  1873.  
  1874. /* FUNCTION:  system_lseek
  1875.  * DESCRIPTION:
  1876.  *    Seek to a position in a file
  1877.  * INPUTS:
  1878.  *    fd-  an open file handle
  1879.  *    off
  1880.  *    wh
  1881.  * OUTPUTS:
  1882.  * RETURNS:
  1883.  * RESTRICTIONS:
  1884.  */
  1885. #define system_lseek (*__nsapi30_table->f_system_lseek)
  1886.  
  1887. /* FUNCTION: system_fclose
  1888.  * DESCRIPTION:
  1889.  *    Close a file.
  1890.  * INPUTS:
  1891.  *    fd- an open file handle from a previous system_fopenXX call.
  1892.  * OUTPUTS:
  1893.  *    none
  1894.  * RETURNS:
  1895.  *    IO_OKAY on success
  1896.  *    IO_ERROR on failure
  1897.  * RESTRICTIONS:
  1898.  */
  1899. #define system_fclose (*__nsapi30_table->f_system_fclose)
  1900.  
  1901. /* FUNCTION: system_stat
  1902.  * DESCRIPTION: 
  1903.  *    Get information about a file on disk
  1904.  * INPUTS:
  1905.  *    name-    the name of the file to be queried
  1906.  * OUTPUTS:
  1907.  *    finfo-   a buffer to receive the file information.
  1908.  * RETURN:
  1909.  *    less-than-zero on failure.
  1910.  *    0 on success.
  1911.  * RESTRICTIONS:
  1912.  *    Within the stat structure, this routine is only guaranteed to return
  1913.  *    st_mode, st_size, st_ctime, and st_mtime. Other stat fields are 
  1914.  *    undefined.
  1915.  */
  1916. #define system_stat (*__nsapi30_table->f_system_stat)
  1917.  
  1918. /* --- File manipulation --------------------------------------------- */
  1919.  
  1920. /* FUNCTION:  system_rename
  1921.  * DESCRIPTION:
  1922.  *    Rename a file on disk.
  1923.  * INPUTS:
  1924.  *    oldpath- old file name
  1925.  *    newpath- new file name
  1926.  * OUTPUTS:
  1927.  *    none
  1928.  * RETURNS:
  1929.  *    less-than-zero on failure
  1930.  *    0 on success
  1931.  * RESTRICTIONS:
  1932.  *    Not guaranteed to work portably on files which are in use.
  1933.  */
  1934. #define system_rename (*__nsapi30_table->f_system_rename)
  1935.  
  1936. /* FUNCTION: system_unlink
  1937.  * DESCRIPTION:
  1938.  *    Remove a file from disk.
  1939.  * INPUTS:
  1940.  *    path- the file to delete
  1941.  * OUTPUTS:
  1942.  *    none
  1943.  * RETURNS:
  1944.  *    less-than-zero on failure
  1945.  *    0 on success
  1946.  * RESTRICTIONS:
  1947.  *    Not guaranteed to work portably on files which are in use.
  1948.  */
  1949. #define system_unlink (*__nsapi30_table->f_system_unlink)
  1950.  
  1951. /* --- File locking -------------------------------------------------- */
  1952.  
  1953. #define system_initlock(fd) (0)
  1954.  
  1955. /* FUNCTION: system_tlock
  1956.  * DESCRIPTION:
  1957.  *    Test for a file lock and grab it if it is available
  1958.  * INPUTS:
  1959.  *    fd- the file to lock
  1960.  * OUTPUTS:
  1961.  *    none
  1962.  * RETURNS:
  1963.  *    0 - if we now hold the lock
  1964.  *    less-than-zero if the lock is held by someone else
  1965.  * RESTRICTIONS:
  1966.  *    1. file locking is process based.  Two threads in the same process
  1967.  *    requesting exclusive access will both be allowed to access the file
  1968.  *    at the same time.
  1969.  */
  1970. #define system_tlock (*__nsapi30_table->f_system_tlock)
  1971.  
  1972. /* FUNCTION:  system_flock
  1973.  * DESCRIPTION:
  1974.  *    Wait for exclusive access to a file
  1975.  * INPUTS:
  1976.  *    fd- the file to lock
  1977.  * OUTPUTS:
  1978.  *    none
  1979.  * RETURNS:
  1980.  *    0 - if we now hold the lock
  1981.  *    less-than-zero if an error occurred
  1982.  * RESTRICTIONS:
  1983.  *    1. file locking is process based.  Two threads in the same process
  1984.  *    requesting exclusive access will both be allowed to access the file
  1985.  *    at the same time.
  1986.  */
  1987. #define system_flock (*__nsapi30_table->f_system_flock)
  1988.  
  1989. /* FUNCTION: system_ulock
  1990.  * DESCRIPTION:
  1991.  *    Release exclusive access to a file
  1992.  * INPUTS:
  1993.  *    fd- the file to lock
  1994.  * OUTPUTS:
  1995.  *    none
  1996.  * RETURNS:
  1997.  *    0 - if we released the lock
  1998.  *    less-than-zero if an error occurred
  1999.  * RESTRICTIONS:
  2000.  *    1. file locking is process based.  Two threads in the same process
  2001.  *    requesting exclusive access will both be allowed to access the file
  2002.  *    at the same time.
  2003.  */
  2004. #define system_ulock (*__nsapi30_table->f_system_ulock)
  2005.  
  2006. /* --- Directory manipulation routines ---------------------------------- */
  2007.  
  2008. #ifdef XP_WIN32
  2009. #define dir_open (*__nsapi30_table->f_dir_open)
  2010. #define dir_read (*__nsapi30_table->f_dir_read)
  2011. #define dir_close (*__nsapi30_table->f_dir_close)
  2012. #endif /* XP_WIN32 */
  2013.  
  2014. /*
  2015.  * create a directory and any of its parents
  2016.  */
  2017. #define dir_create_all (*__nsapi30_table->f_dir_create_all)
  2018.  
  2019. #ifdef XP_WIN32
  2020. #define system_winsockerr (*__nsapi30_table->f_system_winsockerr)
  2021. #define system_winerr (*__nsapi30_table->f_system_winerr)
  2022. #define system_pread (*__nsapi30_table->f_system_pread)
  2023. #define system_pwrite (*__nsapi30_table->f_system_pwrite)
  2024. #define file_unix2local (*__nsapi30_table->f_file_unix2local)
  2025. #endif /* XP_WIN32 */
  2026.  
  2027. #define system_nocoredumps (*__nsapi30_table->f_system_nocoredumps)
  2028. #define file_setinherit (*__nsapi30_table->f_file_setinherit)
  2029. #define file_notfound (*__nsapi30_table->f_file_notfound)
  2030. #define system_errmsg (*__nsapi30_table->f_system_errmsg)
  2031. #define system_errmsg_fn (*__nsapi30_table->f_system_errmsg_fn)
  2032.  
  2033. /* FUNCTION: net_socket
  2034.  * DESCRIPTION:
  2035.  *    Create a new socket.
  2036.  * INPUTS:
  2037.  *    domain-   only supported type is AF_INET
  2038.  *    type-     only supported type is SOCK_STREAM
  2039.  *    protocol- only supported value is 0
  2040.  * OUTPUTS:
  2041.  *    none
  2042.  * RETURNS:
  2043.  *    SYS_NET_ERRORFD on errro
  2044.  *    a valid SYS_NETFD on success
  2045.  * RESTRICTIONS:
  2046.  */
  2047. #define net_socket (*__nsapi30_table->f_net_socket)
  2048.  
  2049. /* FUNCTION: net_listen
  2050.  * DESCRIPTION:
  2051.  *   Set listen backlog for a socket.
  2052.  * INPUTS:
  2053.  *   s- the socket
  2054.  *   backlog- value of backlog to set
  2055.  * OUTPUTS:
  2056.  * RETURNS:
  2057.  *   0 on success
  2058.  *   less-than-zero on failure
  2059.  * RESTRICTIONS:
  2060.  *   Some systems do not return errors even when the requested backlog
  2061.  *   cannot be set (it is too high).  Consult your system manual for 
  2062.  *   details on the maximum value of the backlog.
  2063.  */
  2064. #define net_listen (*__nsapi30_table->f_net_listen)
  2065.  
  2066. /* FUNCTION: net_create_listener
  2067.  * DESCRIPTION:
  2068.  *   Creates a socket for accepting new connection.
  2069.  * INPUTS:
  2070.  * OUTPUTS:
  2071.  * RETURNS:
  2072.  *   SYS_NET_ERRORFD on error.
  2073.  * RESTRICTIONS:
  2074.  *   This is a convenience routine which creates a socket, binds to
  2075.  *   an IP address and port, and sets the listen backlog to 
  2076.  *   net_listenqsize.
  2077.  */
  2078. #define net_create_listener (*__nsapi30_table->f_net_create_listener)
  2079.  
  2080. /* FUNCTION: net_connect
  2081.  * DESCRIPTION:
  2082.  *    Connect a socket to a remote listener
  2083.  * INPUTS:
  2084.  * OUTPUTS:
  2085.  * RETURNS:
  2086.  *    0 on success
  2087.  *    less-than-zero on error
  2088.  * RESTRICTIONS:
  2089.  */
  2090. #define net_connect (*__nsapi30_table->f_net_connect)
  2091.  
  2092. /* FUNCTION: net_getpeername
  2093.  * DESCRIPTION:
  2094.  *    Get the socket address (IP address/port) of the remote host.
  2095.  * INPUTS:
  2096.  *    s-     the socket
  2097.  *    name - the socket address of the remote
  2098.  * OUTPUTS:
  2099.  * RETURNS:
  2100.  * RESTRICTIONS:
  2101.  */
  2102. #define net_getpeername (*__nsapi30_table->f_net_getpeername)
  2103.  
  2104. /* FUNCTION: net_close
  2105.  * DESCRIPTION:
  2106.  *    Close an open socket
  2107.  * INPUTS:
  2108.  *    s- the socket to close
  2109.  * OUTPUTS:
  2110.  *    none
  2111.  * RETURNS:
  2112.  *    0 on success
  2113.  *    less-than-zero on failure
  2114.  * RESTRICTIONS:
  2115.  */
  2116. #define net_close (*__nsapi30_table->f_net_close)
  2117.  
  2118. /* FUNCTION: net_bind
  2119.  * DESCRIPTION:
  2120.  *    Bind to a socket address
  2121.  * INPUTS:
  2122.  *    s-
  2123.  *    name-
  2124.  *    namelen-
  2125.  * OUTPUTS:
  2126.  * RETURNS:
  2127.  * RESTRICTIONS:
  2128.  */
  2129. #define net_bind (*__nsapi30_table->f_net_bind)
  2130.  
  2131. /* FUNCTION: net_accept
  2132.  * DESCRIPTION:
  2133.  *    Accept a connection on a listener socket.
  2134.  * INPUTS:
  2135.  *    s
  2136.  *    addr
  2137.  * OUTPUTS:
  2138.  *    addrlen
  2139.  * RETURNS:
  2140.  * RESTRICTIONS:
  2141.  */
  2142. #define net_accept (*__nsapi30_table->f_net_accept)
  2143.  
  2144. /* FUNCTION: net_read
  2145.  * DESCRIPTION:
  2146.  *    sd
  2147.  *    buf
  2148.  *    sz
  2149.  *    timeout
  2150.  * INPUTS:
  2151.  * OUTPUTS:
  2152.  * RETURNS:
  2153.  *    IO_ERROR on error
  2154.  *    0 if the remote closes the socket
  2155.  *    positive representing the number of bytes successfully read
  2156.  * RESTRICTIONS:
  2157.  *    timeout must be NET_ZERO_TIMEOUT, NET_INFINITE_TIMEOUT, or a positive
  2158.  *    value in seconds
  2159.  */
  2160. #define net_read (*__nsapi30_table->f_net_read)
  2161.  
  2162. /* FUNCTION: net_write
  2163.  * DESCRIPTION:
  2164.  *    Write data to a socket.
  2165.  * INPUTS:
  2166.  *    sd
  2167.  *    buf
  2168.  *    sz
  2169.  * OUTPUTS:
  2170.  * RETURNS:
  2171.  * RESTRICTIONS:
  2172.  *    net_write() is unbuffered.  Specifying many calls to net_write() for 
  2173.  *    small amounts of data is inefficient.
  2174.  */
  2175. #define net_write (*__nsapi30_table->f_net_write)
  2176.  
  2177. /* FUNCTION: net_writev
  2178.  * DESCRIPTION:
  2179.  *    Write vectored data to the socket.
  2180.  * INPUTS:
  2181.  * OUTPUTS:
  2182.  * RETURNS:
  2183.  * RESTRICTIONS:
  2184.  *    net_writev() is unbuffered.  Specifying many calls to net_writev() for 
  2185.  *    small amounts of data is inefficient.
  2186.  */
  2187. #define net_writev (*__nsapi30_table->f_net_writev)
  2188.  
  2189. /* FUNCTION: net_isalive
  2190.  * DESCRIPTION:
  2191.  *    Checks to see if the given socket is still connected to a remote
  2192.  *    host.  The remote host does not see any side effects from this call.
  2193.  * INPUTS:
  2194.  *    sd - the socket
  2195.  * OUTPUTS:
  2196.  *    none
  2197.  * RETURNS:
  2198.  *    0 if the socket is no longer connected
  2199.  *    1 if the socket is still connected.
  2200.  * RESTRICTIONS:
  2201.  */
  2202. #define net_isalive (*__nsapi30_table->f_net_isalive)
  2203.  
  2204. /* FUNCTION: net_ip2host
  2205.  * DESCRIPTION:
  2206.  *    Transforms the given textual IP number into a fully qualified domain
  2207.  *    name (FQDN).   This is similar to calling gethostbyaddr().
  2208.  * INPUTS:
  2209.  *    verify- If 1, specifies that the function should verify the hostname
  2210.  *            returned from the lookup.  This is similar to calling 
  2211.  *            gethostbyname() on the result of the call to gethostbyaddr().
  2212.  * OUTPUTS:
  2213.  * RETURNS:
  2214.  *    The fully qualified domain name, or whatever it can find.
  2215.  *    If it cannot resolve the name at all, returns NULL.
  2216.  * RESTRICTIONS:
  2217.  *    This function is governed by the use of the Server DNS cache. If caching
  2218.  *    is enabled it can take as long as 20 minutes before this function 
  2219.  *    does the lookup again.
  2220.  */
  2221. #define net_ip2host (*__nsapi30_table->f_net_ip2host)
  2222.  
  2223.  
  2224. /* --- OBSOLETE ----------------------------------------------------------
  2225.  * The following macros/functions are obsolete and are only maintained for
  2226.  * compatibility.  Do not use them.
  2227.  * -----------------------------------------------------------------------
  2228.  */
  2229.  
  2230. /* FUNCTION: net_getsockopt
  2231.  * DESCRIPTION:
  2232.  *    Get socket options
  2233.  * INPUTS:
  2234.  * OUTPUTS:
  2235.  * RETURNS:
  2236.  * RESTRICTIONS:
  2237.  *    Because this function is not portable (not all systems support the
  2238.  *    same options), it should be used with caution.
  2239.  */
  2240. #define net_getsockopt (*__nsapi30_table->f_net_getsockopt)
  2241.  
  2242. /* FUNCTION: net_setsockopt
  2243.  * DESCRIPTION:
  2244.  *    Set socket options
  2245.  * INPUTS:
  2246.  * OUTPUTS:
  2247.  * RETURNS:
  2248.  * RESTRICTIONS:
  2249.  *    Because this function is not portable (not all systems support the
  2250.  *    same options), it should be used with caution.
  2251.  */
  2252. #define net_setsockopt (*__nsapi30_table->f_net_setsockopt)
  2253.  
  2254. /* FUNCTION: net_select
  2255.  * DESCRIPTION:
  2256.  *    Wait for IO on a set of sockets.
  2257.  * INPUTS:
  2258.  * OUTPUTS:
  2259.  * RETURNS:
  2260.  *    -1 on error
  2261.  *     0 on timeout
  2262.  *    positive value representing the number of IOs ready
  2263.  * RESTRICTIONS:
  2264.  *    Because this function is not portable (not all systems support the
  2265.  *    same options), it should be used with caution.
  2266.  */
  2267. #define net_select (*__nsapi30_table->f_net_select)
  2268.  
  2269. /* FUNCTION: net_ioctl
  2270.  * DESCRIPTION:
  2271.  *    Set socket options.
  2272.  * INPUTS:
  2273.  * OUTPUTS:
  2274.  * RETURNS:
  2275.  * RESTRICTIONS:
  2276.  *    Because this function is not portable (not all systems support the
  2277.  *    same options), it should be used with caution.
  2278.  */
  2279. #define net_ioctl (*__nsapi30_table->f_net_ioctl)
  2280.  
  2281. /* FUNCTION: net_socketpair
  2282.  * DESCRIPTION:
  2283.  *    Creates a TCP socketpair.
  2284.  * INPUTS:
  2285.  * OUTPUTS:
  2286.  * RETURNS:
  2287.  *    0 on success
  2288.  *   -1 on failure
  2289.  * RESTRICTIONS:
  2290.  *    Because this function is not portable (not all systems support the
  2291.  *    same options), it should be used with caution.
  2292.  */
  2293. #define net_socketpair (*__nsapi30_table->f_net_socketpair)
  2294.  
  2295. #ifdef XP_UNIX
  2296. /* FUNCTION: net_dup2
  2297.  * DESCRIPTION:
  2298.  *    Duplicates a socket to a specific file descriptor
  2299.  * INPUTS:
  2300.  * OUTPUTS:
  2301.  * RETURNS:
  2302.  * RESTRICTIONS:
  2303.  *    Because this function is not portable (not all systems support the
  2304.  *    same options), it should be used with caution.
  2305.  */
  2306. #define net_dup2 (*__nsapi30_table->f_net_dup2)
  2307.  
  2308. /* FUNCTION: net_is_STDOUT
  2309.  * DESCRIPTION:
  2310.  *    Checks if the underlying OS file descriptor for the given 
  2311.  *    SYS_NETFD is the STDOUT filedescriptor
  2312.  * INPUTS:
  2313.  * OUTPUTS:
  2314.  * RETURNS:
  2315.  *    1 if it is STDOUT (1)
  2316.  *    0 otherwise
  2317.  * RESTRICTIONS:
  2318.  *    Because this function is not portable (not all systems support the
  2319.  *    same options), it should be used with caution.
  2320.  */
  2321. #define net_is_STDOUT (*__nsapi30_table->f_net_is_STDOUT)
  2322.  
  2323. /* FUNCTION: net_is_STDIN
  2324.  * DESCRIPTION:
  2325.  *    Checks if the underlying OS file descriptor for the given 
  2326.  *    SYS_NETFD is the STDIN filedescriptor
  2327.  * INPUTS:
  2328.  * OUTPUTS:
  2329.  * RETURNS:
  2330.  *    1 if it is STDIN (0)
  2331.  *    0 otherwise
  2332.  * RESTRICTIONS:
  2333.  *    Because this function is not portable (not all systems support the
  2334.  *    same options), it should be used with caution.
  2335.  */
  2336. #define net_is_STDIN (*__nsapi30_table->f_net_is_STDIN)
  2337. #endif /* XP_UNIX */
  2338.  
  2339. /*
  2340.  * A parameter block is a set of name=value pairs which are generally used 
  2341.  * as parameters, but can be anything. They are kept in a hash table for 
  2342.  * reasonable speed, but if you are doing any intensive modification or
  2343.  * access of them you should probably make a local copy of each parameter
  2344.  * while working.
  2345.  *
  2346.  * When creating a pblock, you specify the hash table size for that pblock.
  2347.  * You should set this size larger if you know that many items will be in 
  2348.  * that pblock, and smaller if only a few will be used or if speed is not
  2349.  * a concern.
  2350.  */
  2351.  
  2352. /*
  2353.  * param_create creates a parameter with the given name and value. If name
  2354.  * and value are non-NULL, they are copied and placed into the new pb_param
  2355.  * struct.
  2356.  */
  2357.  
  2358. #define param_create (*__nsapi30_table->f_param_create)
  2359.  
  2360. /*
  2361.  * param_free frees a given parameter if it's non-NULL, and returns 1 if
  2362.  * p was non-NULL, and 0 if p was NULL.
  2363.  * 
  2364.  * Useful for error checking pblock_remove.
  2365.  */
  2366.  
  2367. #define param_free (*__nsapi30_table->f_param_free)
  2368.  
  2369. /* 
  2370.  * pblock_create creates a new pblock with hash table size n.
  2371.  * 
  2372.  * It returns the newly allocated pblock.
  2373.  */
  2374.  
  2375. #define pblock_create (*__nsapi30_table->f_pblock_create)
  2376.  
  2377. /*
  2378.  * pblock_free frees the given pblock and any entries inside it.
  2379.  * 
  2380.  * If you want to save anything in a pblock, remove its entities with 
  2381.  * pblock_remove first and save the pointers you get.
  2382.  */
  2383.  
  2384. #define pblock_free (*__nsapi30_table->f_pblock_free)
  2385.  
  2386. /*
  2387.  * pblock_findval finds the entry with the given name in pblock pb, and
  2388.  * returns its value, otherwise returns NULL.
  2389.  */
  2390.  
  2391. #define pblock_findval (*__nsapi30_table->f_pblock_findval)
  2392.  
  2393. /*
  2394.  * pblock_nvinsert creates a new parameter with the given name and value
  2395.  * and inserts it into pblock pb. The name and value in the parameter are
  2396.  * also newly allocated. Returns the pb_param it allocated (in case you 
  2397.  * need it).
  2398.  *
  2399.  * pblock_nninsert inserts a numerical value.
  2400.  */
  2401.  
  2402. #define pblock_nvinsert (*__nsapi30_table->f_pblock_nvinsert)
  2403. #define pblock_nninsert (*__nsapi30_table->f_pblock_nninsert)
  2404.  
  2405. /*
  2406.  * pblock_pinsert inserts a pb_param into a pblock.
  2407.  */
  2408.  
  2409. #define pblock_pinsert (*__nsapi30_table->f_pblock_pinsert)
  2410.  
  2411. /*
  2412.  * pblock_str2pblock scans the given string str for parameter pairs
  2413.  * name=value, or name="value". Any \ must be followed by a literal 
  2414.  * character. If a string value is found, with no unescaped = signs, it
  2415.  * will be added with the name 1, 2, 3, etc. depending on whether it was
  2416.  * first, second, third, etc. in the stream (zero doesn't count).
  2417.  * 
  2418.  * Returns the number of parameters added to the table, or -1 upon error.
  2419.  */
  2420.  
  2421. #define pblock_str2pblock (*__nsapi30_table->f_pblock_str2pblock)
  2422.  
  2423. /*
  2424.  * pblock_pblock2str places all of the parameters in the given pblock 
  2425.  * into the given string (NULL if it needs creation). It will re-allocate
  2426.  * more space for the string. Each parameter is separated by a space and of
  2427.  * the form name="value"
  2428.  */
  2429.  
  2430. #define pblock_pblock2str (*__nsapi30_table->f_pblock_pblock2str)
  2431.  
  2432. /*
  2433.  * pblock_copy copies the entries in the given source pblock to the 
  2434.  * destination one. The entries are newly allocated so that the original
  2435.  * pblock may be freed or the new one changed without affecting the other.
  2436.  */
  2437.  
  2438. #define pblock_copy (*__nsapi30_table->f_pblock_copy)
  2439.  
  2440. /*
  2441.  * pblock_dup creates a new pblock and copies the given source pblock
  2442.  * into it.  The entries are newly allocated so that the original pblock
  2443.  * may be freed or the new one changed without affecting the other.
  2444.  */
  2445.  
  2446. #define pblock_dup (*__nsapi30_table->f_pblock_dup)
  2447.  
  2448. /*
  2449.  * pblock_pb2env copies the given pblock into the given environment, with
  2450.  * one new env entry for each name/value pair in the pblock.
  2451.  */
  2452.  
  2453. #define pblock_pb2env (*__nsapi30_table->f_pblock_pb2env)
  2454.  
  2455. /* --------------------------- Internal things ---------------------------- */
  2456. #define pblock_fr (*__nsapi30_table->f_pblock_fr)
  2457. #define pblock_replace (*__nsapi30_table->f_pblock_replace)
  2458.  
  2459. /* pool_create()
  2460.  * Function to create a new pool.
  2461.  * Returns non-NULL on success, NULL on failure.
  2462.  */
  2463. #define pool_create (*__nsapi30_table->f_pool_create)
  2464.  
  2465. /* pool_destroy()
  2466.  * Frees all memory associated with a pool and destroys the pool.
  2467.  */
  2468. #define pool_destroy (*__nsapi30_table->f_pool_destroy)
  2469.  
  2470. /* pool_enabled()
  2471.  * Check if the pools are enabled and a pool is currently set
  2472.  * for this thread.  Return 1 if enabled, 0 if not enabled.
  2473.  */
  2474. #define pool_enabled (*__nsapi30_table->f_pool_enabled)
  2475.  
  2476. #define pool_malloc (*__nsapi30_table->f_pool_malloc)
  2477. #define pool_free (*__nsapi30_table->f_pool_free)
  2478. #define pool_calloc (*__nsapi30_table->f_pool_calloc)
  2479. #define pool_realloc (*__nsapi30_table->f_pool_realloc)
  2480. #define pool_strdup (*__nsapi30_table->f_pool_strdup)
  2481.  
  2482. /*
  2483.  * regexp_valid takes a regular expression exp as input. It returns:
  2484.  * 
  2485.  *  NON_REGEXP      if exp is a standard string
  2486.  *                  (above not used -- always returns VALID_REGEXP!!)
  2487.  *  INVALID_REGEXP  if exp is a regular expression, but invalid
  2488.  *  VALID_REGEXP    if exp is a valid regular expression
  2489.  */
  2490.  
  2491. #define regexp_valid (*__nsapi30_table->f_regexp_valid)
  2492.  
  2493. /*
  2494.  * regexp_match 
  2495.  * 
  2496.  * Takes a prevalidated shell expression exp, and a string str.
  2497.  *
  2498.  * Returns 0 on match and 1 on non-match.
  2499.  */
  2500.  
  2501. #define regexp_match (*__nsapi30_table->f_regexp_match)
  2502.  
  2503. /*
  2504.  * regexp_cmp
  2505.  * 
  2506.  * Same as above, but validates the exp first. 0 on match, 1 on non-match,
  2507.  * -1 on invalid exp. regexp_casecmp does the same thing but is case 
  2508.  * insensitive.
  2509.  */
  2510.  
  2511. #define regexp_cmp (*__nsapi30_table->f_regexp_cmp)
  2512. #define regexp_casecmp (*__nsapi30_table->f_regexp_casecmp)
  2513.  
  2514. /*
  2515.  * sem_init creates a semaphore using the given name and unique 
  2516.  * identification number. filename should be a file accessible to the 
  2517.  * process. Returns SEM_ERROR on error.
  2518.  */
  2519.  
  2520. #define sem_init (*__nsapi30_table->f_sem_init)
  2521.  
  2522. /*
  2523.  * sem_terminate de-allocates the given semaphore.
  2524.  */
  2525.  
  2526. #define sem_terminate (*__nsapi30_table->f_sem_terminate)
  2527.  
  2528. /*
  2529.  * sem_grab attempts to gain exclusive access to the given semaphore. If
  2530.  * it can't get it, the caller will block. Returns -1 on error.
  2531.  */
  2532.  
  2533. #define sem_grab (*__nsapi30_table->f_sem_grab)
  2534. #define sem_tgrab (*__nsapi30_table->f_sem_tgrab)
  2535.  
  2536. /*
  2537.  * sem_release releases this process's exclusive control over the given
  2538.  * semaphore. Returns -1 on error.
  2539.  */
  2540.  
  2541. #define sem_release (*__nsapi30_table->f_sem_release)
  2542.  
  2543. /*
  2544.  * session_create creates a new request structure for the client with the
  2545.  * given socket descriptor and sockaddr.
  2546.  */
  2547.  
  2548. #define session_alloc (*__nsapi30_table->f_session_alloc)
  2549. #define session_fill (*__nsapi30_table->f_session_fill)
  2550. #define session_create (*__nsapi30_table->f_session_create)
  2551.  
  2552. /*
  2553.  * session_free frees the given session
  2554.  */
  2555.  
  2556. #define session_free (*__nsapi30_table->f_session_free)
  2557.  
  2558. #define session_dns_lookup (*__nsapi30_table->f_session_dns_lookup)
  2559.  
  2560. /*
  2561.  *      This describes the API for matching a string with a "shell expression".
  2562.  *      The expressions accepted are based loosely on the expressions accepted
  2563.  *      by zsh.  A shell expression is a string pattern made up of ordinary
  2564.  *      characters and any of the types of pattern sequences listed below.
  2565.  *
  2566.  *      Pattern                 Matches
  2567.  *      *                       zero or more characters
  2568.  *      ?                       exactly one character
  2569.  *      $                       matches the end of string
  2570.  *      [abc]                   matches one instance of any of the characters
  2571.  *                              enclosed in []
  2572.  *      [a-z]                   matches one instance of any character in the
  2573.  *                              specified range of characters
  2574.  *      [^abc]                  matches one instance of any character not
  2575.  *                              in the enclosed set
  2576.  *
  2577.  *      Backslash (\) is used to quote a character that would otherwise be
  2578.  *      considered part of a pattern sequence, e.g. "2\*2=4".
  2579.  *
  2580.  *      The following composite shell expression structures are also
  2581.  *      recognized:
  2582.  *
  2583.  *      shexp1~shexp2           matches any string that matches shexp1,
  2584.  *                              unless the string also matches shexp2
  2585.  *
  2586.  *              Example:  "*~*.netscape.com" matches any string that does
  2587.  *                              not end with ".netscape.com"
  2588.  *
  2589.  *      (shexp1|...|shexpN)     matches any string that matches any one of
  2590.  *                              the ()-enclosed, |-separated shell
  2591.  *                              expressions.
  2592.  */
  2593.  
  2594. /* Determine whether exp is a valid shell expression */
  2595. #define shexp_valid (*__nsapi30_table->f_shexp_valid)
  2596.  
  2597. /*
  2598.  * shexp_match 
  2599.  * 
  2600.  * Takes a prevalidated shell expression exp, and a string str.
  2601.  *
  2602.  * Returns 0 on match and 1 on non-match.
  2603.  */
  2604.  
  2605. #define shexp_match (*__nsapi30_table->f_shexp_match)
  2606.  
  2607.  
  2608. /*
  2609.  * shexp_cmp
  2610.  * 
  2611.  * Same as above, but validates the exp first. 0 on match, 1 on non-match,
  2612.  * -1 on invalid exp. shexp_casecmp does the same thing but is case 
  2613.  * insensitive.
  2614.  */
  2615.  
  2616. #define shexp_cmp (*__nsapi30_table->f_shexp_cmp)
  2617. #define shexp_casecmp (*__nsapi30_table->f_shexp_casecmp)
  2618.  
  2619. /*
  2620.  * Regular expression API - Analogous to shell expression API 
  2621.  */
  2622.  
  2623. #define regexp_valid (*__nsapi30_table->f_regexp_valid)
  2624. #define regexp_match (*__nsapi30_table->f_regexp_match)
  2625. #define regexp_cmp (*__nsapi30_table->f_regexp_cmp)
  2626. #define regexp_casecmp (*__nsapi30_table->f_regexp_casecmp)
  2627.  
  2628.  
  2629. #if defined (SHMEM_UNIX_MMAP) || defined (SHMEM_WIN32_MMAP)
  2630.  
  2631. /*
  2632.  * shmem_alloc allocates a region of shared memory of the given size, using
  2633.  * the given name to avoid conflicts between multiple regions within the
  2634.  * program. The region will not be automatically grown if its boundaries 
  2635.  * are over-run, use shmem_realloc for that. 
  2636.  *
  2637.  * If expose is non-zero and the underlying system supports it, the
  2638.  * file used to create the shared region will be visible to other processes
  2639.  * running on the system.
  2640.  *
  2641.  * name should be unique to the program which calls this routine, otherwise
  2642.  * conflicts will arise.
  2643.  *
  2644.  * Returns a new shared memory region, with the data element being a 
  2645.  * pointer to the shared memory. This function must be called before any
  2646.  * daemon workers are spawned, in order for the handle to the shared region
  2647.  * to be inherited by the children.
  2648.  *
  2649.  * Because of the requirement that the region must be inherited by the
  2650.  * children, the region cannot be re-allocated with a larger size when
  2651.  * necessary.
  2652.  */
  2653. #define shmem_alloc (*__nsapi30_table->f_shmem_alloc)
  2654.  
  2655. /*
  2656.  * shmem_free de-allocates the specified region of shared memory.
  2657.  */
  2658. #define shmem_free (*__nsapi30_table->f_shmem_free)
  2659.  
  2660. #endif  /* SHMEM_UNIX_MMAP || SHMEM_WIN32_MMAP */
  2661.  
  2662. /*
  2663.  * systhread_start creates a thread with the given priority, will allocate
  2664.  * a stack of stksz bytes, and calls fn with arg as its argument. stksz
  2665.  * of zero will allocate a default stack size. 
  2666.  * 
  2667.  * Returns a new SYS_THREAD pointer on success, SYS_THREAD_ERROR on failure.
  2668.  * XXX Priorities are system dependent
  2669.  */
  2670.  
  2671. #define systhread_start (*__nsapi30_table->f_systhread_start)
  2672.  
  2673. /* 
  2674.  * systhread_current returns a handle for the current thread.
  2675.  */
  2676.  
  2677. #define systhread_current (*__nsapi30_table->f_systhread_current)
  2678.  
  2679. /*
  2680.  * systhread_yield yields the processor to another thread
  2681.  */
  2682.  
  2683. #define systhread_yield (*__nsapi30_table->f_systhread_yield)
  2684.  
  2685. /*
  2686.  * systhread_attach makes an existing thread an NSPR thread.
  2687.  */
  2688. #define systhread_attach (*__nsapi30_table->f_systhread_attach)
  2689.  
  2690. /*
  2691.  * Detaches a thread that was attached.
  2692.  */
  2693.  
  2694. #define systhread_detach (*__nsapi30_table->f_systhread_detach)
  2695.  
  2696. /* 
  2697.  * systhread_terminate terminates the thread that is passed in.
  2698.  */
  2699. #define systhread_terminate (*__nsapi30_table->f_systhread_terminate)
  2700.  
  2701. /*
  2702.  * systhread_sleep puts the calling thread to sleep for the given number
  2703.  * of milliseconds.
  2704.  */
  2705. #define systhread_sleep (*__nsapi30_table->f_systhread_sleep)
  2706.  
  2707. /*
  2708.  * systhread_init initializes the threading system. name is a name for the
  2709.  * program for debugging.
  2710.  */
  2711.  
  2712. #define systhread_init (*__nsapi30_table->f_systhread_init)
  2713.  
  2714. /*
  2715.  * systhread_timerset starts or re-sets the interrupt timer for a thread
  2716.  * system. This should be considered a suggestion as most systems don't allow
  2717.  * the timer interval to be changed.
  2718.  */
  2719.  
  2720. #define systhread_timerset (*__nsapi30_table->f_systhread_timerset)
  2721.  
  2722. /*
  2723.  * newkey allocates a new integer id for thread-private data. Use this
  2724.  * key to identify a variable which you want to appear differently 
  2725.  * between threads, and then use setdata to associate a value with this
  2726.  * key for each thread.
  2727.  */
  2728. #define systhread_newkey (*__nsapi30_table->f_systhread_newkey)
  2729.  
  2730. /*
  2731.  * Get data that has been previously associated with key in this thread.
  2732.  * Returns NULL if setkey has not been called with this key by this 
  2733.  * thread previously, or the data that was previously used with setkey
  2734.  * by this thread with this key.
  2735.  */
  2736. #define systhread_getdata (*__nsapi30_table->f_systhread_getdata)
  2737.  
  2738. /*
  2739.  * Associate data with the given key number in this thread.
  2740.  */
  2741. #define systhread_setdata (*__nsapi30_table->f_systhread_setdata)
  2742.  
  2743. /*
  2744.  * Set the default stack size for threads created via systhr_start
  2745.  */
  2746. #define systhread_set_default_stacksize (*__nsapi30_table->f_systhread_set_default_stacksize)
  2747.  
  2748. /*
  2749.  *      A hodge podge of utility functions and standard functions which 
  2750.  *      are unavailable on certain systems
  2751.  */
  2752.  
  2753. /*
  2754.  * getline scans in buf until it finds a LF or CRLF, storing the string in
  2755.  * l. It will terminate the string and return:
  2756.  * 
  2757.  *  0 when done, with the scanned line (minus CR or LF) in l
  2758.  *  1 upon EOF, with the scanned line (minus CR or LF) in l
  2759.  * -1 on error with the error description in l (uses lineno for information)
  2760.  */
  2761.  
  2762. #define util_getline (*__nsapi30_table->f_util_getline)
  2763.  
  2764. /*
  2765.  * env_create creates a new environment with the given env, with n new
  2766.  * entries, and places the current position that you should add your
  2767.  * entries with at pos.
  2768.  * 
  2769.  * If env is NULL, it will allocate a new one. If not, it will reallocate
  2770.  * that one.
  2771.  */
  2772.  
  2773. #define util_env_create (*__nsapi30_table->f_util_env_create)
  2774.  
  2775. /*
  2776.  * util_env_str allocates a string from the given name and value and
  2777.  * returns it. It does not check for things like = signs in name.
  2778.  */
  2779.  
  2780. #define util_env_str (*__nsapi30_table->f_util_env_str)
  2781.  
  2782. /*
  2783.  * env_replace replaces the occurrence of the given variable with the 
  2784.  * value you give.
  2785.  */
  2786.  
  2787. #define util_env_replace (*__nsapi30_table->f_util_env_replace)
  2788.  
  2789. /*
  2790.  * util_env_free frees an environment.
  2791.  */
  2792.  
  2793. #define util_env_free (*__nsapi30_table->f_util_env_free)
  2794.  
  2795. /*
  2796.  * util_env_copy copies an env
  2797.  */
  2798. #define util_env_copy (*__nsapi30_table->f_util_env_copy)
  2799.  
  2800. /*
  2801.  * util_env_find looks through env for the named string. Returns the
  2802.  * corresponding value if the named string is found, or NULL if not.
  2803.  */
  2804. #define util_env_find (*__nsapi30_table->f_util_env_find)
  2805.  
  2806. /*
  2807.  * hostname gets the local hostname. Returns NULL if it can't find a FQDN.
  2808.  * You are free to realloc or free this string.
  2809.  */
  2810.  
  2811. #define util_hostname (*__nsapi30_table->f_util_hostname)
  2812.  
  2813. /*
  2814.  * chdir2path changes the current directory to the one that the file
  2815.  * path is in. path should point to a file. Caveat: path must be a writable
  2816.  * string. It won't get modified permanently.
  2817.  */
  2818.  
  2819. #define util_chdir2path (*__nsapi30_table->f_util_chdir2path)
  2820.  
  2821. /*
  2822.  * is_mozilla checks if the given user-agent is mozilla, of at least
  2823.  * the given major and minor revisions. These are strings to avoid 
  2824.  * ambiguities like 1.56 > 1.5
  2825.  */
  2826.  
  2827. #define util_is_mozilla (*__nsapi30_table->f_util_is_mozilla)
  2828.  
  2829. /*
  2830.  * is_url will return 1 if the given string seems to be a URL, or will 
  2831.  * return 0 otherwise. 
  2832.  * 
  2833.  * Because of stupid news URLs, this will return 1 if the string has 
  2834.  * all alphabetic characters up to the first colon and will not check for 
  2835.  * the double slash.
  2836.  */
  2837.  
  2838. #define util_is_url (*__nsapi30_table->f_util_is_url)
  2839.  
  2840. /*
  2841.  * util_later_than checks the date in the string ims, and if that date is 
  2842.  * later than or equal to the one in the tm struct lms, then it returns 1.
  2843.  *
  2844.  * util_time_equal is above, but checks for exact equality.
  2845.  *
  2846.  * Handles RFC 822, 850, and ctime formats.
  2847.  */
  2848.  
  2849. #define util_later_than (*__nsapi30_table->f_util_later_than)
  2850. #define util_time_equal (*__nsapi30_table->f_util_time_equal)
  2851.  
  2852. /* 
  2853.  * util_str_time_equal checks the character-string dates are equal.
  2854.  * Supports rfc1123 and rfc850 formats.  t1 must be rfc1123
  2855.  * Returns 0 if equal, -1 otherwise
  2856.  */
  2857. #define util_str_time_equal (*__nsapi30_table->f_util_str_time_equal)
  2858.  
  2859. /*
  2860.  * util_uri_is_evil returns 1 if a URL has ../ or // in it.
  2861.  */
  2862. #define util_uri_is_evil (*__nsapi30_table->f_util_uri_is_evil)
  2863.  
  2864. /*
  2865.  * util_uri_parse gets rid of /../, /./, and //.
  2866.  * 
  2867.  * Assumes that either the string starts with a /, or the string will
  2868.  * not .. right off of its beginning.  As such, ../foo.gif will
  2869.  * not be changed, although /../foo.gif will become /foo.gif.
  2870.  */
  2871.  
  2872. #define util_uri_parse (*__nsapi30_table->f_util_uri_parse)
  2873.  
  2874. /*
  2875.  * util_uri_unescape unescapes the given URI in place (% conversions only).
  2876.  */
  2877.  
  2878. #define util_uri_unescape (*__nsapi30_table->f_util_uri_unescape)
  2879.  
  2880. /*
  2881.  * util_uri_escape escapes any nasty chars in s and copies the string into d.
  2882.  * If d is NULL, it will allocate and return a properly sized string.
  2883.  * Warning: does not check bounds on a given d.
  2884.  *
  2885.  * util_url_escape does the same thing but does it for a url, i.e. ?:+ is 
  2886.  * not escaped.
  2887.  */
  2888.  
  2889. #define util_uri_escape (*__nsapi30_table->f_util_uri_escape)
  2890. #define util_url_escape (*__nsapi30_table->f_util_url_escape)
  2891.  
  2892. /*
  2893.  * util_sh_escape places a \ in front of any shell-special characters.
  2894.  * Returns a newly-allocated copy of the string.
  2895.  */
  2896.  
  2897. #define util_sh_escape (*__nsapi30_table->f_util_sh_escape)
  2898.  
  2899. /*
  2900.  * util_mime_separator generates a new MIME separator into the given buffer.
  2901.  * The buffer should be more than 4 + 3*10 + 1 bytes long. A CRLF is prepended
  2902.  * to the beginning of the string, along with two dashes. The string is null
  2903.  * terminated, with no CRLF. The intent is that you create your content-type
  2904.  * header by accessing &sep[4], and afterwards print sep followed by CRLF
  2905.  * for message boundaries.
  2906.  *
  2907.  * Returns the length of the string.
  2908.  */
  2909. #define util_mime_separator (*__nsapi30_table->f_util_mime_separator)
  2910.  
  2911. /*
  2912.  * util_itoa converts the given integer to a string into a.
  2913.  */
  2914.  
  2915. #define util_itoa (*__nsapi30_table->f_util_itoa)
  2916.  
  2917. /*
  2918.  * util_vsprintf and util_sprintf are simplified clones of the System V 
  2919.  * vsprintf and sprintf routines.
  2920.  * 
  2921.  * Returns the number of characters printed. Only handles %d and %s,
  2922.  * does not handle any width or precision.
  2923.  */
  2924.  
  2925. #define util_vsprintf (*__nsapi30_table->f_util_vsprintf)
  2926. #define util_sprintf (*__nsapi30_table->f_util_sprintf)
  2927.  
  2928. /* These routines perform bounds checks. */
  2929. #define util_vsnprintf (*__nsapi30_table->f_util_vsnprintf)
  2930. #define util_snprintf (*__nsapi30_table->f_util_snprintf)
  2931.  
  2932. /* util_strftime()
  2933.  * Thread safe version of strftime.
  2934.  * No bounds checking is done s.  t must be a valid tm structure.
  2935.  */
  2936. #define util_strftime (*__nsapi30_table->f_util_strftime)
  2937.  
  2938. /* Various thread safe routines. */
  2939.  
  2940. #define util_strtok (*__nsapi30_table->f_util_strtok)
  2941. #define util_localtime (*__nsapi30_table->f_util_localtime)
  2942. #define util_ctime (*__nsapi30_table->f_util_ctime)
  2943. #define util_strerror (*__nsapi30_table->f_util_strerror)
  2944. #define util_gmtime (*__nsapi30_table->f_util_gmtime)
  2945. #define util_asctime (*__nsapi30_table->f_util_asctime)
  2946.  
  2947. #ifdef NEED_STRCASECMP
  2948. #define util_strcasecmp (*__nsapi30_table->f_util_strcasecmp)
  2949. #define strcasecmp(s1, s2) util_strcasecmp(s1, s2)
  2950. #endif /* NEED_STRCASECMP */
  2951.  
  2952. #ifdef NEED_STRNCASECMP
  2953. #define util_strncasecmp (*__nsapi30_table->f_util_strncasecmp)
  2954. #define strncasecmp(s1, s2, n) util_strncasecmp(s1, s2, n)
  2955. #endif /* NEED_STRNCASECMP */
  2956.  
  2957. #ifdef XP_UNIX
  2958.  
  2959. /*
  2960.  * can_exec returns 1 if you can execute the file described by finfo, and 
  2961.  * 0 if you can't.
  2962.  */
  2963.  
  2964. #define util_can_exec (*__nsapi30_table->f_util_can_exec)
  2965.  
  2966. /*
  2967.  * Thread safe getpwnam
  2968.  */
  2969. #define util_getpwnam (*__nsapi30_table->f_util_getpwnam)
  2970.  
  2971. #define util_waitpid (*__nsapi30_table->f_util_waitpid)
  2972.  
  2973. #endif /* XP_UNIX */
  2974.  
  2975. #ifdef XP_WIN32
  2976.  
  2977. /* util_delete_directory()
  2978.  * This routine deletes all the files in a directory.  If delete_directory is
  2979.  * TRUE it will also delete the directory itself.
  2980.  */
  2981. #define util_delete_directory (*__nsapi30_table->f_util_delete_directory)
  2982.  
  2983. #endif /* XP_WIN32 */
  2984.  
  2985. /*
  2986.  * conf_init reads the given configuration file and sets any non-default
  2987.  * parameters to their given setting.
  2988.  */
  2989. #define conf_init (*__nsapi30_table->f_conf_init)
  2990. #define conf_run_init_functions (*__nsapi30_table->f_conf_run_init_functions)
  2991.  
  2992. /*
  2993.  * conf_terminate frees any data the conf routines may be holding.
  2994.  */
  2995. #define conf_terminate (*__nsapi30_table->f_conf_terminate)
  2996.  
  2997. /*
  2998.  * conf_getServerString returns the Server ID string
  2999.  */
  3000. #define conf_getServerString (*__nsapi30_table->f_conf_getServerString)
  3001.  
  3002. /*
  3003.  * Get a structure with the global variables for this server.
  3004.  */
  3005. #define conf_getglobals (*__nsapi30_table->f_conf_getglobals)
  3006.  
  3007. /*
  3008.  * func_init reads the static FuncStruct arrays and creates the global 
  3009.  * function table from them.
  3010.  *
  3011.  * func_init will only read from the static arrays defined in func.c.
  3012.  */
  3013. #define func_init (*__nsapi30_table->f_func_init)
  3014.  
  3015. /*
  3016.  * func_find returns a pointer to the function named name, or NULL if none
  3017.  * exists.
  3018.  */
  3019. #define func_find (*__nsapi30_table->f_func_find)
  3020.  
  3021. /* DO NOT USE this function.
  3022.  */
  3023. #define func_set_native_thread_flag (*__nsapi30_table->f_func_set_native_thread_flag)
  3024.  
  3025. /*
  3026.  * func_exec will try to execute the function whose name is the "fn" entry
  3027.  * in the given pblock. If name is not found, it will log a misconfig of
  3028.  * missing fn parameter. If it can't find it, it will log that. In these
  3029.  * cases it will return REQ_ABORTED. Otherwise, it will return what the 
  3030.  * function being executed returns.
  3031.  */
  3032. #define func_exec (*__nsapi30_table->f_func_exec)
  3033.  
  3034. /*
  3035.  * func_replace will replace a function in the server's function table with
  3036.  * another.  Returns the FuncPtr to the old function if it replaces the 
  3037.  * function, otherwise it returns 0.
  3038.  */
  3039. #define func_replace (*__nsapi30_table->f_func_replace)
  3040.  
  3041. /*
  3042.  * func_insert dynamically inserts a named function into the server's
  3043.  * table of functions. Returns the FuncStruct it keeps in internal 
  3044.  * databases, because on server restart you are responsible for freeing 
  3045.  * (or not) its contents.
  3046.  */
  3047. #define func_insert (*__nsapi30_table->f_func_insert)
  3048. #define object_execute (*__nsapi30_table->f_object_execute)
  3049.  
  3050. /*
  3051.  * gets the first line of an HTTP request
  3052.  */
  3053. #define http_find_request (*__nsapi30_table->f_http_find_request)
  3054.  
  3055. /*
  3056.  * parses the first line of an HTTP request
  3057.  */
  3058. #define http_parse_request (*__nsapi30_table->f_http_parse_request)
  3059.  
  3060. /*
  3061.  * Scans HTTP headers from the given netbuf, and places them in headers.
  3062.  * If netbuf is NULL, the session's inbuf is used.
  3063.  * 
  3064.  * Folded lines are joined and the linefeed removed (but not the whitespace).
  3065.  * If there are any repeat headers they are joined and the two field bodies
  3066.  * separated by a comma and space.
  3067.  *
  3068.  * t should be a string of length REQ_MAX_LINE. This is a convenience to
  3069.  * req.c so that we don't use too much runtime stack.
  3070.  *
  3071.  * Session is an optional parameter. Use NULL if you wish. It's used for
  3072.  * error logs.
  3073.  */
  3074. #define http_scan_headers (*__nsapi30_table->f_http_scan_headers)
  3075.  
  3076. /*
  3077.  * Starts the HTTP response. If HTTP/0.9, does nothing. If 1.0, sends header.
  3078.  * If this returns REQ_NOACTION, the method was head and no body should be
  3079.  * sent. Otherwise, it will return REQ_PROCEED.
  3080.  */
  3081. #define http_start_response (*__nsapi30_table->f_http_start_response)
  3082.  
  3083. /*
  3084.  * http_hdrs2env takes the entries from the given pblock and converts them
  3085.  * to an environment. 
  3086.  *
  3087.  * Each name entry will be made uppercase, prefixed with HTTP_ and any
  3088.  * occurrence of - will be converted to _.
  3089.  */
  3090. #define http_hdrs2env (*__nsapi30_table->f_http_hdrs2env)
  3091.  
  3092. /*
  3093.  * http_status sets status to the code n, with reason string r. If r is
  3094.  * NULL, the server will attempt to find one for the given status code.
  3095.  * If it finds none, it will give "Because I felt like it."
  3096.  */
  3097. #define http_status (*__nsapi30_table->f_http_status)
  3098.  
  3099. /*
  3100.  * http_set_finfo sets content-length and last-modified
  3101.  */
  3102.  
  3103. #define http_set_finfo (*__nsapi30_table->f_http_set_finfo)
  3104.  
  3105. /*
  3106.  * Takes the given pblock and prints headers into the given buffer at 
  3107.  * position pos. Returns the buffer, reallocated if needed. Modifies pos.
  3108.  */
  3109. #define http_dump822 (*__nsapi30_table->f_http_dump822)
  3110.  
  3111. /*
  3112.  * Finishes a request. For HTTP, this just closes the socket.
  3113.  */
  3114. #define http_finish_request (*__nsapi30_table->f_http_finish_request)
  3115.  
  3116. /*
  3117.  * http_handle_session processes each request generated by Session
  3118.  */
  3119. #define http_handle_session (*__nsapi30_table->f_http_handle_session)
  3120.  
  3121. /*
  3122.  * http_uri2url takes the give URI prefix and URI suffix and creates a 
  3123.  * newly-allocated full URL from them of the form
  3124.  * http://(server):(port)(prefix)(suffix)
  3125.  * 
  3126.  * If you want either prefix or suffix to be skipped, use "" instead of NULL.
  3127.  *
  3128.  * Normally, the server hostname is taken from the ServerName parameter in
  3129.  * magnus.conf. The newer function http_uri2url_dynamic should be used when 
  3130.  * a Session and Request structure are available, to ensure that the browser
  3131.  * gets redirected to the exact host they were originally referencing.
  3132.  */
  3133.  
  3134. #define http_uri2url (*__nsapi30_table->f_http_uri2url)
  3135. #define http_uri2url_dynamic (*__nsapi30_table->f_http_uri2url_dynamic)
  3136.  
  3137. /*
  3138.  * http_set_keepalive_timeout sets the number of seconds to wait for a new
  3139.  * request to come from a persistent connection. Returns nothing. Intended
  3140.  * to be called at server startup only.
  3141.  *
  3142.  * Specifying a timeout of zero will disable persistent connections and allow
  3143.  * browsers to request only one file per connection.
  3144.  */
  3145. #define http_set_keepalive_timeout (*__nsapi30_table->f_http_set_keepalive_timeout)
  3146.  
  3147. /*
  3148.  * log_error logs an error of the given degree from the function func
  3149.  * and formats the arguments with the printf() style fmt. Returns whether the
  3150.  * log was successful. Records the current date.
  3151.  *
  3152.  * sn and rq are optional parameters. If given, information about the client
  3153.  * will be reported.
  3154.  */
  3155. #define log_error_v (*__nsapi30_table->f_log_error_v)
  3156. #define log_error (*__nsapi30_table->f_log_error)
  3157.  
  3158. /*
  3159.  *  Internal use only 
  3160.  */
  3161. #define log_ereport_v (*__nsapi30_table->f_log_ereport_v)
  3162. #define log_ereport (*__nsapi30_table->f_log_ereport)
  3163.  
  3164. /*
  3165.  * object_create will create a new object and return a pointer to it.
  3166.  * It will allocate space for nd directive types and set name accordingly.
  3167.  */
  3168. #define object_create (*__nsapi30_table->f_object_create)
  3169.  
  3170. /*
  3171.  * object_free will free an object and any data associated with it.
  3172.  */
  3173. #define object_free (*__nsapi30_table->f_object_free)
  3174.  
  3175. /*
  3176.  * object_add_directive will add a new directive to the dtable for 
  3177.  * the directive class at position dc.
  3178.  */
  3179. #define object_add_directive (*__nsapi30_table->f_object_add_directive)
  3180.  
  3181. /*
  3182.  * Executes the directive specified by inst within the context of the
  3183.  * given session and request structures. Returns what the executed function
  3184.  * returned (one of the REQ_* codes defined in req.h).
  3185.  *
  3186.  * This prototype uses void * for Request * in order to avoid including
  3187.  * all of req.h. 
  3188.  *
  3189.  */
  3190.  
  3191. /*
  3192.  * objset_scan_buffer will scan through buffer, looking for object 
  3193.  * configuration information, and adding them to the object set os if it 
  3194.  * finds any. If os is NULL it will allocate a new object set.
  3195.  *
  3196.  * If any error occurs (syntax error, premature EOF) this function will
  3197.  * free os, print an error message into errstr, and return NULL.
  3198.  * This is because a config. file error is viewed as a catastrophic error
  3199.  * from which httpd should not try to recover. If httpd were to continue
  3200.  * after an error, it would not behave as the admin. expected and he/she
  3201.  * may not notice until it's too late.
  3202.  *
  3203.  * Upon EOF the file will not be closed.
  3204.  */
  3205. #define objset_scan_buffer (*__nsapi30_table->f_objset_scan_buffer)
  3206.  
  3207. /*
  3208.  * objset_create creates a new object set and returns a pointer to it.
  3209.  */
  3210. #define objset_create (*__nsapi30_table->f_objset_create)
  3211.  
  3212. /*
  3213.  * objset_free will free an object set, any associated objects, and any
  3214.  * associated Init functions.
  3215.  */
  3216. #define objset_free (*__nsapi30_table->f_objset_free)
  3217.  
  3218. /*
  3219.  * objset_free_setonly frees only the object set, and not the associated
  3220.  * objects or init functions.
  3221.  */
  3222. #define objset_free_setonly (*__nsapi30_table->f_objset_free_setonly)
  3223.  
  3224. /*
  3225.  * objset_new_object will add a new object to objset with the specified
  3226.  * name. It returns a pointer to the new object (which may be anywhere in 
  3227.  * the objset).
  3228.  */
  3229. #define objset_new_object (*__nsapi30_table->f_objset_new_object)
  3230.  
  3231. /*
  3232.  * objset_add_object will add the existing object to os.
  3233.  */
  3234. #define objset_add_object (*__nsapi30_table->f_objset_add_object)
  3235.  
  3236. /*
  3237.  * objset_add_init will add the initialization function specified by 
  3238.  * initfn to the given object set. Modifies os->initfns.
  3239.  */
  3240. #define objset_add_init (*__nsapi30_table->f_objset_add_init)
  3241.  
  3242. /*
  3243.  * objset_findbyname will find the object in objset having the given name,
  3244.  * and return the object if found, and NULL otherwise.
  3245.  * ign is a set of objects to ignore.
  3246.  */
  3247. #define objset_findbyname (*__nsapi30_table->f_objset_findbyname)
  3248.  
  3249. /*
  3250.  * objset_findbyppath will find the object in objset having the given 
  3251.  * partial path entry. Returns object if found, NULL otherwise.
  3252.  * ign is a set of objects to ignore.
  3253.  */
  3254. #define objset_findbyppath (*__nsapi30_table->f_objset_findbyppath)
  3255.  
  3256. /*
  3257.  * request_create creates a new request structure.
  3258.  */
  3259. #define request_create (*__nsapi30_table->f_request_create)
  3260.  
  3261. /*
  3262.  * request_free destroys a request structure.
  3263.  */
  3264. #define request_free (*__nsapi30_table->f_request_free)
  3265.  
  3266. /*
  3267.  * Restarts a request for a given URI internally. If rq is non-NULL, the
  3268.  * function will keep the old request's headers and protocol, but with a new 
  3269.  * URI and method of GET. If the previous method was HEAD, this is preserved.
  3270.  * Any other method becomes GET. You may assume that if you give it a request
  3271.  * structure that it will use the same structure.
  3272.  *
  3273.  * Once you have this new Request, you must then do what you want with
  3274.  * it (e.g. send the object back, perform uri2path translation, etc.)
  3275.  */
  3276. #define request_restart_internal (*__nsapi30_table->f_request_restart_internal)
  3277.  
  3278. /*
  3279.  * request_header finds the named header depending on the requesting 
  3280.  * protocol. If possible, it will not load headers until the first is 
  3281.  * requested. You have to watch out because this can return REQ_ABORTED.
  3282.  */
  3283. #define request_header (*__nsapi30_table->f_request_header)
  3284.  
  3285. /*
  3286.  * request_loadheaders just makes sure the headers have been loaded.
  3287.  */
  3288. #define request_loadheaders (*__nsapi30_table->f_request_loadheaders)
  3289.  
  3290. /*
  3291.  * request_stat_path tries to stat path. If path is NULL, it will look in
  3292.  * the vars pblock for "path". If the stat is successful, it returns the stat 
  3293.  * structure. If not, returns NULL and leaves a message in rq->staterr. If a 
  3294.  * previous call to this function was successful, and path is the same, the 
  3295.  * function will simply return the previously found value.
  3296.  *
  3297.  * User functions should not free this structure.
  3298.  */
  3299.  
  3300. #define request_stat_path (*__nsapi30_table->f_request_stat_path)
  3301.  
  3302. /*
  3303.  * Random number generation
  3304.  *
  3305.  *      random_create - create a new random number context
  3306.  *      random_update - update a context with random data
  3307.  *      random_generate - generate random bytes
  3308.  *      random_destroy - destroy a random number context
  3309.  */
  3310.  
  3311. #define random_create (*__nsapi30_table->f_random_create)
  3312. #define random_update (*__nsapi30_table->f_random_update)
  3313. #define random_generate (*__nsapi30_table->f_random_generate)
  3314. #define random_destroy (*__nsapi30_table->f_random_destroy)
  3315.  
  3316. /*
  3317.  * MD5 hash routines
  3318.  *
  3319.  *      md5hash_create - create an MD5 hash context
  3320.  *      md5hash_copy - make a copy of an MD5 hash context
  3321.  *      md5hash_begin - initialize an MD5 hash context
  3322.  *      md5hash_update - update MD5 hash with more input data
  3323.  *      md5hash_end - finalize MD5 hash and get result
  3324.  *      md5hash_destroy - destroy an MD5 hash context
  3325.  *      md5hash_data - compute MD5 hash of data in one step
  3326.  */
  3327.  
  3328. #define md5hash_create (*__nsapi30_table->f_md5hash_create)
  3329. #define md5hash_copy (*__nsapi30_table->f_md5hash_copy)
  3330. #define md5hash_begin (*__nsapi30_table->f_md5hash_begin)
  3331. #define md5hash_update (*__nsapi30_table->f_md5hash_update)
  3332. #define md5hash_end (*__nsapi30_table->f_md5hash_end)
  3333. #define md5hash_destroy (*__nsapi30_table->f_md5hash_destroy)
  3334. #define md5hash_data (*__nsapi30_table->f_md5hash_data)
  3335.  
  3336. /*
  3337.  * ACL_SetupEval -
  3338.  *  Setup environment and call ACL_EvalTestRights.
  3339.  */
  3340. #define ACL_SetupEval (*__nsapi30_table->f_ACL_SetupEval)
  3341.  
  3342. /*
  3343.  * servact_translate_uri
  3344.  * Returns the translated path (filename) for the given uri, NULL otherwise.
  3345.  * If authentication is required for the given uri, nothing is returned even
  3346.  * if the current user has authenticated to that area.
  3347.  */
  3348. #define servact_translate_uri (*__nsapi30_table->f_servact_translate_uri)
  3349.  
  3350. #endif /* !INTNSAPI */
  3351.  
  3352. #ifndef FILE_MMAP
  3353. #define filebuf_open_nostat(fd,sz,finfo) filebuf_open(fd,sz)
  3354. #endif
  3355.  
  3356. #ifdef XP_UNIX
  3357. #define dir_open opendir
  3358. #define dir_read readdir
  3359. #define dir_close closedir
  3360. #define dir_create(path) mkdir(path, 0755)
  3361. #define dir_remove rmdir
  3362. #define system_chdir chdir
  3363. #define file_unix2local(path,p2) strcpy(p2,path)
  3364. #endif /* XP_UNIX */
  3365.  
  3366. #ifdef XP_WIN32
  3367. #define dir_create _mkdir
  3368. #define dir_remove _rmdir
  3369. #define system_chdir SetCurrentDirectory
  3370. #endif /* XP_WIN32 */
  3371.  
  3372. /*
  3373.  * Thread-safe variants of localtime and gmtime
  3374.  */
  3375. #define system_localtime(curtime, ret) util_localtime(curtime, ret)
  3376. #define system_gmtime(curtime, ret) util_gmtime(curtime, ret)
  3377.  
  3378. /* 
  3379.  * pblock_find finds the entry with the given name in pblock pb.
  3380.  *
  3381.  * If it is successful, it returns the param block. If not, it returns NULL.
  3382.  */
  3383.  
  3384. #define pblock_find(name, pb) (pblock_fr(name,pb,0))
  3385.  
  3386. /*
  3387.  * pblock_remove behaves exactly like pblock_find, but removes the given
  3388.  * entry from pb.
  3389.  */
  3390.  
  3391. #define pblock_remove(name, pb) (pblock_fr(name,pb,1))
  3392.  
  3393. /*
  3394.  * session_dns returns the DNS hostname of the client of this session,
  3395.  * and inserts it into the client pblock. Returns NULL if unavailable.
  3396.  */
  3397.  
  3398. #define session_dns(sn) session_dns_lookup(sn, 0)
  3399.  
  3400. /*
  3401.  * session_maxdns looks up a hostname from an IP address, and then verifies 
  3402.  * that the host is really who they claim to be. 
  3403.  */
  3404.  
  3405. #define session_maxdns(sn) session_dns_lookup(sn, 1)
  3406.  
  3407. #define protocol_find_request http_find_request
  3408. #define protocol_parse_request http_parse_request
  3409. #define protocol_scan_headers http_scan_headers
  3410. #define protocol_start_response http_start_response
  3411. #define protocol_status http_status
  3412. #define protocol_set_finfo http_set_finfo
  3413. #define protocol_finish_request http_finish_request
  3414. #define protocol_handle_session http_handle_session
  3415. #define protocol_uri2url http_uri2url
  3416. #define protocol_uri2url_dynamic http_uri2url_dynamic
  3417. #define protocol_set_keepalive_timeout http_set_keepalive_timeout
  3418.  
  3419. /* XXXrobm temporary compatibility */
  3420. #define request_uri2path servact_uri2path
  3421. #define request_pathchecks servact_pathchecks
  3422. #define request_fileinfo servact_fileinfo
  3423. #define request_service servact_service
  3424.  
  3425. #define request_handle_processed servact_handle_processed
  3426. #define request_translate_uri servact_translate_uri
  3427. #define request_finderror servact_finderror
  3428.  
  3429. /* --- OBSOLETE ----------------------------------------------------------
  3430.  * The following macros/functions are obsolete and are only maintained for
  3431.  * compatibility.  Do not use them. 11-19-96
  3432.  * -----------------------------------------------------------------------
  3433.  */
  3434.  
  3435. #define SYS_STDERR STDERR_FILENO
  3436.  
  3437. #ifdef XP_WIN32
  3438.  
  3439. typedef HANDLE pid_t;
  3440.  
  3441. #define ERROR_PIPE \
  3442.     (ERROR_BROKEN_PIPE | ERROR_BAD_PIPE |\
  3443.      ERROR_PIPE_BUSY | ERROR_PIPE_LISTENING | ERROR_PIPE_NOT_CONNECTED)
  3444. #define CONVERT_TO_PRINTABLE_FORMAT(Filename)     \
  3445. {                                               \
  3446.     register char *s;                           \
  3447.     if (Filename)                               \
  3448.     for (s = Filename; *s; s++)                \
  3449.         if ( *s    == '\\')                       \
  3450.             *s = '/';                           \
  3451. }
  3452. #define CONVERT_TO_NATIVE_FS(Filename)        \
  3453. {                                              \
  3454.     register char *s;                          \
  3455.     if (Filename)                           \
  3456.         for (s = Filename; *s; s++)        \
  3457.             if ( *s    == '/')                   \
  3458.                 *s = '\\';                   \
  3459. }                                     
  3460.  
  3461. #ifdef INTNSAPI
  3462. NSAPI_PUBLIC extern nsapi_dispatch_t *__nsapi30_table;
  3463. #else
  3464. __declspec(dllimport) nsapi_dispatch_t *__nsapi30_table;
  3465. #endif /* INTNSAPI */
  3466.  
  3467. #else /* !XP_WIN32 */
  3468.  
  3469. NSAPI_PUBLIC extern nsapi_dispatch_t *__nsapi30_table;
  3470.  
  3471. #endif /* XP_WIN32 */
  3472.  
  3473. #endif /* !PUBLIC_NSAPI_H */
  3474.